本文档只是简要描述,详细内容请查看官网
RapidJson 只需要几个 .h 文件即可使用,非常方便。直接 include 相应库即可:
1 | #include"rapidjson/document.h" |
1.解析
1 | Document dom; |
2.输出
1 | StringBuffer buf; |
3.查询
对象和数组使用 [ ] 查询
对于值:
.IsNull()是否是 null.IsInt()是否是 int.GetInt()返回 int 值(必须是 int,否则会爆炸)
GetString 等函数同上。
4.修改/添加
= 符号是个好东西。
对于数组,使用
PushBack(值, 内存分配器)对于对象,使用
AddMember(键, 值, 内存分配器)
获取内存分配器:Document::AllocatorType& allocator = document.GetAllocator()
5.注意:构造函数
构造 Value 时,默认就是普通值,如果想要创建空数组、空对象,请使用 Value o(kObjectType); Value a(kArrayType);