boost::property_tree::ptree解析json陣列
阿新 • • 發佈:2018-12-14
json陣列如下:
{"var_name":"var1","positions":[0.1,0.1,0.1,0.1,0.1,0.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; }