boost::property_tree::ptree解析json数组

json数组如下:

{"var_name":"var1","positions":[0.1,0.1,0.1,0.1,0.1,0.1]},;

    1

代码:

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>

std::stringstream str_stream(json_content);
boost::property_tree::ptree root;
boost::property_tree::read_json(str_stream, root);
 // get_child得到数组对象
boost::property_tree::ptree positions_array = root.get_child("positions");
boost::property_tree::ptree::iterator pos = positions_array.begin();
for(; pos != positions_array.end(); ++pos)
{
   double value = pos->second.get_value<double>();
   std::cout<<"value "<<job <<std::endl;
}

猜你喜欢

转载自blog.csdn.net/dddxxxx/article/details/87889270