Increase access float array from JSON data

I have JSON data collected using boost, and I cannot figure out how to access some of the data in the array:

JSON data: {"dvm_gnd": {"num": 4, "value": [1,2,3,4]}, "xx_gn": {"num: 1," value ": 5}}

I can easily get "num" and a single value of "5" using:

BOOST_FOREACH(ptree::value_type &v, pt) { float value = v.second.get<float>("value") } 

However, I have no idea how to access the elements of the array? What returns ptree.get ()?

thanks

Ross

+4
source share
2 answers

Try the following:

 BOOST_FOREACH(ptree::value_type &v, pt.get_child("dvm_gnd.value")) { float value = v.second.data(); } 
+3
source

I am sure that you have passed so far, but in case someone encounters this, ptree puts these array values ​​in the form of children with an empty name, so the code you need looks something like this:

 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 standard version of get

+2
source

Source: https://habr.com/ru/post/1348131/


All Articles