rapidjson的read和write的sample

2020-12-13 02:58

阅读:354

标签:style   class   blog   code   color   get   

#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.Parse0>(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<:stringbuffer> writer(buffer);
    document.Accept(writer);
    auto out = buffer.GetString();
    log("out: %s", out);
}

 

rapidjson的read和write的sample,搜素材,soscw.com

rapidjson的read和write的sample

标签:style   class   blog   code   color   get   

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

上一篇:python 管道符

下一篇:java Https工具类


评论


亲,登录后才可以留言!