RapidJSON Document的RAII封装类。
More...
#include <njson.h>
|
| | ncjson (const char *ajsonstr) |
| | 从JSON字符串构造。
|
|
| ncjson () |
| | 默认构造函数,创建空文档。
|
| void | set_object () |
| | 将文档设为Object类型。
|
| bool | parsecheck () |
| | 检查JSON解析是否成功。
|
| rapidjson::Document & | doc () |
| | 获取底层RapidJSON Document引用。
|
| rapidjson::Document::AllocatorType & | allocator () |
| | 获取内存分配器引用。
|
| const char * | nonformat_str () |
| | 获取紧凑格式的JSON字符串。
|
| const char * | str () |
| | 获取美化格式的JSON字符串。
|
|
| static std::string | vstr (const rapidjson::Value *ajson, bool pretty=false) |
| | 将RapidJSON Value转换为字符串。
|
RapidJSON Document的RAII封装类。
提供JSON字符串的解析、内存管理、紧凑/美化输出等功能。 支持从JSON字符串构造或创建空文档。
- Note
- 内部管理RapidJSON的Allocator生命周期。
◆ ncjson()
| ngl::ncjson::ncjson |
( |
const char * | ajsonstr | ) |
|
|
inlineexplicit |
从JSON字符串构造。
- Parameters
-
| ajsonstr | JSON字符串,解析失败时parsecheck()返回false |
◆ allocator()
| rapidjson::Document::AllocatorType & ngl::ncjson::allocator |
( |
| ) |
|
|
inline |
获取内存分配器引用。
- Returns
- rapidjson::Document::AllocatorType& 分配器引用
◆ doc()
| rapidjson::Document & ngl::ncjson::doc |
( |
| ) |
|
|
inline |
获取底层RapidJSON Document引用。
- Returns
- rapidjson::Document& 文档对象引用
◆ nonformat_str()
| const char * ngl::ncjson::nonformat_str |
( |
| ) |
|
|
inline |
获取紧凑格式的JSON字符串。
结果缓存在内部,下次调用前指针有效。
- Returns
- const char* 紧凑JSON字符串指针
◆ parsecheck()
| bool ngl::ncjson::parsecheck |
( |
| ) |
|
|
inline |
检查JSON解析是否成功。
- Returns
- true 解析成功
-
false 解析失败
◆ set_object()
| void ngl::ncjson::set_object |
( |
| ) |
|
|
inline |
将文档设为Object类型。
调用后可通过push方法添加成员。
◆ str()
| const char * ngl::ncjson::str |
( |
| ) |
|
|
inline |
获取美化格式的JSON字符串。
结果缓存在内部,下次调用前指针有效。主要用于诊断和导出配置。
- Returns
- const char* 美化JSON字符串指针
◆ vstr()
| std::string ngl::ncjson::vstr |
( |
const rapidjson::Value * | ajson, |
|
|
bool | pretty = false ) |
|
inlinestatic |
将RapidJSON Value转换为字符串。
- Parameters
-
| ajson | JSON值指针 |
| pretty | 是否美化输出,默认为false(紧凑格式) |
- Returns
- std::string JSON字符串,ajson为nullptr时返回空字符串
The documentation for this class was generated from the following file:
- E:/GitHub/ngl_server/public/cpp/tools/tab/json/njson.h