rapidjson安装使用
·
前言:仅个人小记。
正文
由于 rapidjson是 “header-only”的C++库,故而直接将头文件目录拷贝到系统目录或者指定目录即可完成安装。
参考材料:
rapidjson代码仓库 https://github.com/Tencent/rapidjson
rapidjson 文档 https://rapidjson.org/md_doc_stream.html
git clone https://github.com/Tencent/rapidjson.git
sudo cp -r /rapidjson/include/rapidjson /usr/local/include # 拷贝到系统目录
# 执行测试用例
cd rapidjson/example/simpledom
g++ -std=c++17 simpledom.cpp
./a.out
样例代码
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <iostream>
using namespace rapidjson;
int main() {
// 1. Parse a JSON string into DOM.
const char* json = "{\"project\":\"rapidjson\",\"stars\":10}";
Document d;
d.Parse(json);
// 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;
return 0;
}
执行结果:

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)