首页 > Windows开发 > 详细

rapidjson的read和write的sample

时间:2014-06-18 21:05:58      阅读:676      评论:0      收藏:0      [点我收藏+]
#include "json/document.h"
#include "json/prettywriter.h"
#include "json/stringbuffer.h"

void test()
{
 //read json
    char json[100] = "{ \"hello\" : \"world\" }";
    rapidjson::Document d;
    d.Parse<0>(json);
    log("out %s\n", d["hello"].GetString());
    log("out %s\n", json);

    //write json
    rapidjson::Document document;
    document.SetObject();
    rapidjson::Document::AllocatorType& allocator = document.GetAllocator();

    rapidjson::Value array(rapidjson::kArrayType);

    for (int i = 0; i < 10; i++)
    {
        rapidjson::Value object(rapidjson::kObjectType);
        object.AddMember("id", 1, allocator);
        object.AddMember("name", "test", allocator);
        object.AddMember("version", 1.01, allocator);
        object.AddMember("vip", true, allocator);

        array.PushBack(object, allocator);
    }

    document.AddMember("title", "PLAYER INFO", allocator);
    document.AddMember("players", array, allocator);

    rapidjson::StringBuffer buffer;
    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
    document.Accept(writer);
    auto out = buffer.GetString();
    log("out: %s", out);
}

 

rapidjson的read和write的sample,布布扣,bubuko.com

rapidjson的read和write的sample

原文:http://www.cnblogs.com/ziyouchutuwenwu/p/3790322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!