前言:仅个人小记。
正文
由于 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 DOMStringBuffer buffer;Writer<StringBuffer> writer(buffer);d.Accept(writer);// Output {"project":"rapidjson","stars":11}std::cout << buffer.GetString() << std::endl;return 0;
}
执行结果:
