rapidjson使用样例
2016-12-30 10:54
411 查看
rapidjson库解析测试代码
rapidjson默认支持的字符格式是utf-8的,一般中间接口是json文件的话存储为utf-8比较通用一些。如果是unicode的需要转换。但从源码中的ch类型看,应该是支持泛型的,具体在用到了可以仔细研究一下。
这篇文档中有json解析相关库的性能比较,rapidjson还是各方面均衡比较突出的。https://github.com/miloyip/nativejson-benchmark
库下载
官网:http://rapidjson.org/下载:https://github.com/miloyip/rapidjson/
文件包含
代码样例
#include "..\..\3rd\include\rapidjson\document.h" #include "..\..\3rd\include\rapidjson\writer.h" #include "..\..\3rd\include\rapidjson\stringbuffer.h" #include <iostream> using namespace rapidjson; void rapidjson_test_char() { // 1. Parse a JSON string into DOM. const char* json1 = "{\"project\":\"rapidjson\",\"stars\":10}"; Document d; d.Parse(json1); // 2. Modify it by DOM. Value& s = d["stars"]; s.SetInt(s.GetInt() + 1); // 3. Stringify the DOM StringBuffer buffer; Writer<StringBuffer> writer(buffer); d.Accept(writer); // Output {"project":"rapidjson","stars":11} std::cout << buffer.GetString() << std::endl; printf("\n"); //解析第二个例子 //{"dictVersion": 1,"key": "word","value": "test"} const char* json2 = "{\"dictVersion\":1,\"key\":\"word\",\"value\":\"test\"}"; d.Parse(json2); if (d.HasParseError()) { printf("Parse error!!\n"); return ; } if(d.HasMember("dictVersion")) { printf("The dictVersion is:%d\n", d["dictVersion"].GetInt()); } if(d.HasMember("key")) { printf("The key is:%s\n", d["key"].GetString()); } if(d.HasMember("value")) { printf("The value is:%s\n", d["value"].GetString()); } }
样例测试结果
相关文章推荐
- [rapidjson]_[C/C++]_[rapidjson库使用简单介绍]
- [cocos2dx 3.0 (四)] CocoStudio生成Json文件 + 使用rapidjson获取Json数据
- rapidjson 使用
- rapidjson 使用例子
- rapidjson初探——使用C++解析json
- 使用rapidjson实现了TouchVG的序列化适配器类
- rapidjson的使用例子
- cocos2dx 3.2 定义自己使用rapidjson阅读json数据
- rapidjson常见使用示例
- Json 使用样例
- Cocos2d-x教程(24)-rapidJson使用方法
- Cocos Studio生成Json文件并使用rapidjson获取Json数据
- rapidjson 使用教程
- rapidjson使用总结
- Json文件 使用rapidjson获取Json数据
- 【cocos2dx】rapidjson使用方法以及中文显示的解决方法
- Cocos Studio生成Json文件并使用rapidjson获取Json数据
- 【cocos2dx】使用rapidjson获取Json数据
- 使用rapidjson生成json串
- RapidJSON 代码剖析(二):使用 SSE4.2 优化字符串扫描