rapidjson 添加删除对象
2016-06-30 14:49
591 查看
rapidjson我就不介绍了,以后有机会在补上。
直接上代码
直接上代码
#include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include <stdlib.h> void func() { rapidjson::Document * ptr_doc = new rapidjson::Document(); ptr_doc->Parse("{}"); rapidjson::Document::AllocatorType&allocator = ptr_doc->GetAllocator(); rapidjson::Value current_gameplay(rapidjson::kObjectType); rapidjson::Value current_gameplay_achievements(rapidjson::kObjectType); ptr_doc->AddMember("current_gameplay", current_gameplay, allocator);//对象添加 ptr_doc->AddMember("current_gameplay_achievements", current_gameplay_achievements, allocator); rapidjson::Value user(rapidjson::kObjectType); if (!(*ptr_doc)["current_gameplay"].GetObject().HasMember("user"))//判断是否user对象 { (*ptr_doc)["current_gameplay"].AddMember("user", user, allocator);//current_gameplay对象添加user对象 } rapidjson::Value strObject(rapidjson::kStringType); strObject.SetString("123"); (*ptr_doc)["current_gameplay"]["user"].AddMember("id", strObject, allocator);//current_gameplay的user对象添加 id:"123"; (*ptr_doc)["current_gameplay"]["user"]["id"].SetString("321");//current_gameplay的user对象修改为 id:"321"; (*ptr_doc)["current_gameplay"]["user"].RemoveMember("id");//current_gameplay的user对象删除id项 rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); ptr_doc->Accept(writer); auto msgToString = buffer.GetString(); printf("info:%s", msgToString); }
相关文章推荐
- Cocos2d-x 制作JSON字符串的方法
- rapidjson使用
- 【c++】rapidjson实践
- rapidjson使用总结
- 【cocos2dx】rapidjson使用方法以及中文显示的解决方法
- 【cocos2dx】rapidjson使用方法以及中文显示的解决方法【续】
- Name of an object member must be a string
- cocos2dx学习之rapidjson库json数据解析
- [cocos2dx 3.0 (四)] CocoStudio生成Json文件 + 使用rapidjson获取Json数据
- rapidjson 简单封装
- Cocos数据篇[3.4](2) ——Json数据操作
- 修复一个由宏引起的rapidjson编译失败问题
- rapidjson的使用例子
- rapidjson使用样例
- C++ 封装RapidJson把一个类Json序列化和反序列化
- Rapidjson的简单使用(拼接json串,存取文件中的json,解析json串)
- json解析开源代码【C++】
- 基于 树莓派&opencv&face++开发考勤机(一)
- C++项目RapidJson的详细用法总结
- NVIDIA Jetson TX1 系列开发教程之十二:libcurl、RapidJSON安装