json数据操作类
More...
#include <sttnet.h>
|
| static int | getValue (const std::string &oriStr, std::string &result, const std::string &type="value", const std::string &name="a", const int &num=0) |
| | 提取 JSON 字符串中指定字段的值或嵌套结构。
|
| |
| static std::string | toString (const Json::Value &val) |
| | 将 Json::Value 序列化为紧凑 JSON 文本。
|
| |
| static Json::Value | toJsonArray (const std::string &str) |
| | 解析 JSON 字符串为 Json::Value。
|
| |
| template<class T1, class T2> |
| static std::string | createJson (T1 first, T2 second) |
| | 创建仅包含一个键值对的 JSON 字符串。
|
| |
| template<class T1, class T2, class... Args> |
| static std::string | createJson (T1 first, T2 second, Args... args) |
| | 创建多个键值对组成的 JSON 字符串(递归变参模板)。
|
| |
| template<class T> |
| static std::string | createArray (T first) |
| | 创建只包含一个元素的 JSON 数组字符串。
|
| |
| template<class T, class... Args> |
| static std::string | createArray (T first, Args... args) |
| | 创建多个元素组成的 JSON 数组字符串(递归变参模板)。
|
| |
| static std::string | jsonAdd (const std::string &a, const std::string &b) |
| | 将两个 JSON 字符串拼接为一个有效的 JSON(适用于对象或数组拼接)。
|
| |
| static std::string & | jsonFormatify (const std::string &a, std::string &b) |
| | 将格式化后的 JSON 字符串去除缩进、空格等变成紧凑格式。
|
| |
| static std::string & | jsonToUTF8 (const std::string &input, std::string &output) |
| | 将 JSON 字符串中的 Unicode 转义序列转换为 UTF-8 字符。
|
| |
◆ createArray() [1/2]
template<class T>
| static std::string stt::data::JsonHelper::createArray |
( |
T | first | ) |
|
|
inlinestatic |
创建只包含一个元素的 JSON 数组字符串。
- Template Parameters
-
- Parameters
-
- Returns
- std::string JSON 数组字符串。
◆ createArray() [2/2]
template<class T, class... Args>
| static std::string stt::data::JsonHelper::createArray |
( |
T | first, |
|
|
Args... | args ) |
|
inlinestatic |
创建多个元素组成的 JSON 数组字符串(递归变参模板)。
- Template Parameters
-
- Parameters
-
- Returns
- std::string 拼接完成的 JSON 数组字符串。
◆ createJson() [1/2]
template<class T1, class T2>
| static std::string stt::data::JsonHelper::createJson |
( |
T1 | first, |
|
|
T2 | second ) |
|
inlinestatic |
创建仅包含一个键值对的 JSON 字符串。
- Template Parameters
-
| T1 | 键的类型,通常为 std::string。 |
| T2 | 值的类型,可为任意可被 Json::Value 接收的类型。 |
- Parameters
-
- Returns
- std::string JSON 字符串。
◆ createJson() [2/2]
template<class T1, class T2, class... Args>
| static std::string stt::data::JsonHelper::createJson |
( |
T1 | first, |
|
|
T2 | second, |
|
|
Args... | args ) |
|
inlinestatic |
创建多个键值对组成的 JSON 字符串(递归变参模板)。
- Template Parameters
-
| T1 | 第一个键的类型。 |
| T2 | 第一个值的类型。 |
| Args | 其余成对出现的键值参数类型。 |
- Parameters
-
| first | 第一个键。 |
| second | 第一个值。 |
| args | 其余键值参数。 |
- Returns
- std::string 拼接完成的 JSON 字符串。
◆ getValue()
| static int stt::data::JsonHelper::getValue |
( |
const std::string & | oriStr, |
|
|
std::string & | result, |
|
|
const std::string & | type = "value", |
|
|
const std::string & | name = "a", |
|
|
const int & | num = 0 ) |
|
static |
提取 JSON 字符串中指定字段的值或嵌套结构。
- Parameters
-
| oriStr | 原始 JSON 字符串。 |
| result | 存储返回值的字符串引用。 |
| type | 类型模式,可选值:value, arrayvalue。分别为普通json对象里面的值,数组对象里面的值。 |
| name | JSON 中的键名(仅适用于 value)。 |
| num | 数组索引位置(从0开始)(仅适用于 arrayvalue)。 |
- Returns
- -1:提取失败 0:返回非json对象 1:返回json对象
◆ jsonAdd()
| static std::string stt::data::JsonHelper::jsonAdd |
( |
const std::string & | a, |
|
|
const std::string & | b ) |
|
static |
将两个 JSON 字符串拼接为一个有效的 JSON(适用于对象或数组拼接)。
- Parameters
-
| a | 第一个 JSON 字符串。 |
| b | 第二个 JSON 字符串。 |
- Returns
- std::string 拼接后的 JSON 字符串。
◆ jsonFormatify()
| static std::string & stt::data::JsonHelper::jsonFormatify |
( |
const std::string & | a, |
|
|
std::string & | b ) |
|
static |
将格式化后的 JSON 字符串去除缩进、空格等变成紧凑格式。
- Parameters
-
| a | 输入的 JSON 字符串。 |
| b | 存储格式化结果的引用。 |
- Returns
- std::string& 紧凑格式的字符串引用。
◆ jsonToUTF8()
| static std::string & stt::data::JsonHelper::jsonToUTF8 |
( |
const std::string & | input, |
|
|
std::string & | output ) |
|
static |
将 JSON 字符串中的 Unicode 转义序列转换为 UTF-8 字符。
- Parameters
-
| input | 含有 Unicode 编码的 JSON 字符串。 |
| output | 存储转换后字符串的引用。 |
- Returns
- std::string& 返回转换后的字符串引用。
◆ toJsonArray()
| static Json::Value stt::data::JsonHelper::toJsonArray |
( |
const std::string & | str | ) |
|
|
static |
解析 JSON 字符串为 Json::Value。
- Parameters
-
- Returns
- Json::Value 解析后的 JSON 对象或数组。
◆ toString()
| static std::string stt::data::JsonHelper::toString |
( |
const Json::Value & | val | ) |
|
|
static |
将 Json::Value 序列化为紧凑 JSON 文本。
- Parameters
-
- Returns
- 合法 JSON 文本;字符串值也会包含 JSON 引号。
The documentation for this class was generated from the following file: