首页 > 代码库 > rapidjson的read和write的sample
rapidjson的read和write的sample
#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);}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。