boost库之生成json数据
boost库头文件,ptree.hpp文件为生成json数据头文件,json_parser.hpp文件为解析json数据头文件
#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"
jsonobject示例
boost::property_tree::ptree repdata;
repdata.put("publisherexception",publisherexception.toStdString());
repdata.put("publisherstatus","0");
repdata.put("publisherinformation",getPublisherInformations.toStdString());
repdata.put("status",status.toStdString());
repdata.put("errorcode",errorcode.toStdString());
repdata.put("errorinformation",errorinformation.toStdString());
repdata.put("errnumber",QString::number(errornumber).toStdString());
repdata.put("waittime",QString::number(waittotaltime).toStdString());
repdata.put("disctoatal",QString::number(discburned).toStdString());
输出为
jsonarray 示例
boost::property_tree::ptree array;
boost::property_tree::ptree ptrees;
array.push_back(make_pair("",repdata));
ptrees.push_back(std::make_pair("array",array));
std::stringstream repdata_status;
write_json(repdata_status, ptrees);
输出
不带key值的数组和json解析留坑待编辑