用boost的PropertyTree json_parser 生成json字符串
// test.cpp
#include
#include
#include
#include
#include
using namespace std;
using namespace boost::property_tree;
int main(){
ptree pt_1,pt_11,pt_12;
pt_11.put("id","3445");
pt_11.put("age",29);
pt_11.put("name","chen");
pt_12.push_back(make_pair("",pt_11));
pt_12.push_back(make_pair("",pt_11));
//replace or create child node "data"
pt_1.put_child("data",pt_12);
ostringstream os;
write_json(os,pt_1);
cout<
system("pause");
return 0;
}
// =========== 产生如下JSON串: ===============
/*
{
"data":
[
{
"id": "3445",
"age": "29",
"name": "chen"
},
{
"id": "3445",
"age": "29",
"name": "chen"
}
]
}
*/
阅读(3731) | 评论(0) | 转发(0) |