json序列化
#ifndef FND_JSON_OBJECT_H
#define FND_JSON_OBJECT_H
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <string>
using ptree = boost::property_tree::ptree;
inline std::string ptreeToJsonString(const ptree& tree)
{
std::stringstream ss;
boost::property_tree::write_json(ss, tree, false);
return ss.str();
}
#endif
int main()
{
//解析
ptree tree;
std::stringstream ss(std::string(***,));
boost::property_tree::read_json(ss,tree);
std::cout<<"client: '";
std::cout<<tree.get<std::string>("name");
std::cout<<"'says'";
std::cout<<tree.get<std::string>("information");
std::cout<<"'
";
//生成json
ptree tree;
tree.push("name",name);
std::string outbuffer = ptreeToJsonString(tree);
}