I have some JSON data collected via boost and I can not work out how to access some of the data that is in an array:
JSON data : {"dvm_gnd": {"num" : 4, "value": [1,2,3,4]}, "xx_gn" : {"num : 1, "value": 5}}
I can easily get the "num" and single "value" (5) out using:
BOOST_FOREACH(ptree::value_type &v, pt) {
float value = v.second.get<float>("value")
}
However I have n开发者_JAVA百科o idea how to access the elements of the array out? What does the ptree.get() return?
Thanks
Ross
Try this:
BOOST_FOREACH(ptree::value_type &v, pt.get_child("dvm_gnd.value")) {
float value = v.second.data();
}
I'm sure you've moved on by now, but in case someone else comes across this, ptree puts those array values as children with a blank name, so the code you want looks something like:
BOOST_FOREACH(const ptree::value_type &v, pt.get_child("dvm_gnd.value")) {
float value = v.second.get<float>("");
}
Or you can use the optional or default value version of get
精彩评论