在C ++中将json值转换为int [英] Convert json value to int in c++
本文介绍了在C ++中将json值转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
Json::Reader reader
,该值存储在Json::Value root
此根目录包含"age"和"id",我想将root ["age"]转换为int.
This root contains "age" and "id" and I want to convert root["age"] to int.
我尝试使用.str()将其转换为字符串,但无法获取.
I tried to convert it to string using .str() but could not get.
有什么建议吗?
推荐答案
在jsoncpp
中,它们在Json::Value
对象上提供了辅助方法.您只需在值上调用asInt()
方法即可将其转换.
In jsoncpp
they provide helper methods on the Json::Value
object. You can merely call the asInt()
method on the value to convert it.
int ageAsInt = root["age"].asInt()
这篇关于在C ++中将json值转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文