Chinaunix首页 | 论坛 | 博客
  • 博客访问: 137225
  • 博文数量: 35
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-09 12:22
个人简介

http://www.76ku.cn

文章分类

全部博文(35)

文章存档

2011年(1)

2010年(17)

2007年(17)

我的朋友

分类: C/C++

2010-06-28 21:11:03

用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) |
0

上一篇:C++ string

下一篇:PHP验证码(彩色+字体倾斜)

给主人留下些什么吧!~~