STTNet 0.7.0
载入中...
搜索中...
未找到
stt::data::JsonHelper类 参考

json数据操作类 更多...

#include <sttnet.h>

静态 Public 成员函数

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 字符。
 

详细描述

json数据操作类

成员函数说明

◆ createArray() [1/2]

template<class T>
static std::string stt::data::JsonHelper::createArray ( T first)
inlinestatic

创建只包含一个元素的 JSON 数组字符串。

模板参数
T任意类型。
参数
first第一个元素。
返回
std::string JSON 数组字符串。

◆ createArray() [2/2]

template<class T, class... Args>
static std::string stt::data::JsonHelper::createArray ( T first,
Args... args )
inlinestatic

创建多个元素组成的 JSON 数组字符串(递归变参模板)。

模板参数
T第一个元素类型。
Args其余元素类型。
参数
first第一个元素。
args其余元素。
返回
std::string 拼接完成的 JSON 数组字符串。

◆ createJson() [1/2]

template<class T1, class T2>
static std::string stt::data::JsonHelper::createJson ( T1 first,
T2 second )
inlinestatic

创建仅包含一个键值对的 JSON 字符串。

模板参数
T1键的类型,通常为 std::string。
T2值的类型,可为任意可被 Json::Value 接收的类型。
参数
first键。
second值。
返回
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 字符串(递归变参模板)。

模板参数
T1第一个键的类型。
T2第一个值的类型。
Args其余成对出现的键值参数类型。
参数
first第一个键。
second第一个值。
args其余键值参数。
返回
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 字符串中指定字段的值或嵌套结构。

参数
oriStr原始 JSON 字符串。
result存储返回值的字符串引用。
type类型模式,可选值:value, arrayvalue。分别为普通json对象里面的值,数组对象里面的值。
nameJSON 中的键名(仅适用于 value)。
num数组索引位置(从0开始)(仅适用于 arrayvalue)。
返回
-1:提取失败 0:返回非json对象 1:返回json对象

◆ jsonAdd()

static std::string stt::data::JsonHelper::jsonAdd ( const std::string & a,
const std::string & b )
static

将两个 JSON 字符串拼接为一个有效的 JSON(适用于对象或数组拼接)。

参数
a第一个 JSON 字符串。
b第二个 JSON 字符串。
返回
std::string 拼接后的 JSON 字符串。

◆ jsonFormatify()

static std::string & stt::data::JsonHelper::jsonFormatify ( const std::string & a,
std::string & b )
static

将格式化后的 JSON 字符串去除缩进、空格等变成紧凑格式。

参数
a输入的 JSON 字符串。
b存储格式化结果的引用。
返回
std::string& 紧凑格式的字符串引用。

◆ jsonToUTF8()

static std::string & stt::data::JsonHelper::jsonToUTF8 ( const std::string & input,
std::string & output )
static

将 JSON 字符串中的 Unicode 转义序列转换为 UTF-8 字符。

参数
input含有 Unicode 编码的 JSON 字符串。
output存储转换后字符串的引用。
返回
std::string& 返回转换后的字符串引用。

◆ toJsonArray()

static Json::Value stt::data::JsonHelper::toJsonArray ( const std::string & str)
static

解析 JSON 字符串为 Json::Value。

参数
str输入的 JSON 字符串。
返回
Json::Value 解析后的 JSON 对象或数组。

◆ toString()

static std::string stt::data::JsonHelper::toString ( const Json::Value & val)
static

将 Json::Value 序列化为紧凑 JSON 文本。

参数
valJSON 值。
返回
合法 JSON 文本;字符串值也会包含 JSON 引号。

该类的文档由以下文件生成: