🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
ast::JsonValue类 参考

#include <JsonValue.hpp>

Public 成员函数

 JsonValue ()
 
 JsonValue (bool value)
 
 JsonValue (int value)
 
 JsonValue (double value)
 
 JsonValue (const char *value)
 
 JsonValue (const std::string &value)
 
 JsonValue (StringView value)
 
 JsonValue (const std::vector< JsonValue > &values)
 
 JsonValue (const std::map< std::string, JsonValue > &values)
 
 JsonValue (const JsonValue &other)
 
 JsonValue (JsonValue &&other) noexcept
 
JsonValueoperator= (const JsonValue &other)
 
JsonValueoperator= (JsonValue &&other) noexcept
 
template<typename T >
JsonValueoperator= (T value)
 
 ~JsonValue ()
 
EJsonValueType type () const
 
bool isNull () const
 
bool isBool () const
 
bool isNumber () const
 
bool isString () const
 
bool isArray () const
 
bool isObject () const
 
bool toBool (bool defaultValue=false) const
 
int toInt (int defaultValue=0) const
 
double toDouble (double defaultValue=0.0) const
 
std::string toString (StringView defaultValue=StringView()) const
 
const std::vector< JsonValue > & getArray (const std::vector< JsonValue > &defaultValue=std::vector< JsonValue >()) const
 
const std::map< std::string, JsonValue > & getObject (const std::map< std::string, JsonValue > &defaultValue=std::map< std::string, JsonValue >()) const
 
size_t size () const
 
 operator bool () const
 
 operator int () const
 
 operator double () const
 
 operator std::string () const
 
JsonValueoperator[] (size_t index)
 
JsonValueoperator[] (int index)
 
const JsonValueoperator[] (size_t index) const
 
const JsonValueoperator[] (int index) const
 
JsonValueoperator[] (const std::string &key)
 
JsonValueoperator[] (const char *key)
 
const JsonValueoperator[] (const std::string &key) const
 
const JsonValueoperator[] (const char *key) const
 
void setNull ()
 
void setBool (bool value)
 
void setInt (int value)
 
void setDouble (double value)
 
void setString (StringView value)
 
void setArray (const std::vector< JsonValue > &values={})
 
void setObject (const std::map< std::string, JsonValue > &values={})
 
void clear ()
 
void insert (const std::string &name, JsonValue value)
 
template<typename T >
void insert (const std::string &name, T value)
 
void append (JsonValue value)
 
template<typename T >
void append (T value)
 
std::string toJsonString (int indent=0) const
 
errc_t parseFromString (StringView json)
 
errc_t parseFromFile (StringView filepath)
 

静态 Public 成员函数

static JsonValue FromString (StringView json)
 
static JsonValue FromFile (const StringView filePath)
 

详细描述

JSON 值类

提供 JSON 值的表示和操作

构造及析构函数说明

◆ JsonValue() [1/10]

ast::JsonValue::JsonValue ( bool value)
explicit

从布尔值构造

参数
value布尔值

◆ JsonValue() [2/10]

ast::JsonValue::JsonValue ( int value)
explicit

从整数构造

参数
value整数值

◆ JsonValue() [3/10]

ast::JsonValue::JsonValue ( double value)
explicit

从双精度浮点数构造

参数
value双精度浮点数值

◆ JsonValue() [4/10]

ast::JsonValue::JsonValue ( const char * value)
explicit

从字符串构造

参数
value字符串值

◆ JsonValue() [5/10]

ast::JsonValue::JsonValue ( const std::string & value)
explicit

从字符串构造

参数
value字符串值

◆ JsonValue() [6/10]

ast::JsonValue::JsonValue ( StringView value)
explicit

从字符串视图构造

参数
value字符串视图

◆ JsonValue() [7/10]

ast::JsonValue::JsonValue ( const std::vector< JsonValue > & values)
explicit

从数组构造

参数
valuesJSON 值数组

◆ JsonValue() [8/10]

ast::JsonValue::JsonValue ( const std::map< std::string, JsonValue > & values)
explicit

从对象构造

参数
valuesJSON 对象(键值对映射)

◆ JsonValue() [9/10]

ast::JsonValue::JsonValue ( const JsonValue & other)

拷贝构造函数

参数
other其他 JSON 值

◆ JsonValue() [10/10]

ast::JsonValue::JsonValue ( JsonValue && other)
noexcept

移动构造函数

参数
other其他 JSON 值

成员函数说明

◆ append() [1/2]

void ast::JsonValue::append ( JsonValue value)

插入键值对(模板重载)

参数
index数组索引
value键值

◆ append() [2/2]

template<typename T >
void ast::JsonValue::append ( T value)
inline

插入键值对(模板重载)

参数
index数组索引
value键值

◆ FromFile()

JsonValue ast::JsonValue::FromFile ( const StringView filePath)
static

从文件构造 JSON 值

参数
filePathJSON 文件路径
返回
JSON 值

◆ FromString()

JsonValue ast::JsonValue::FromString ( StringView json)
static

从字符串构造 JSON 值

参数
jsonJSON 字符串
返回
JSON 值

◆ getArray()

const std::vector< JsonValue > & ast::JsonValue::getArray ( const std::vector< JsonValue > & defaultValue = std::vector<JsonValue>()) const

获取数组引用(安全版本)

参数
defaultValue默认值
返回
数组引用,如果类型不匹配返回默认值

◆ getObject()

const std::map< std::string, JsonValue > & ast::JsonValue::getObject ( const std::map< std::string, JsonValue > & defaultValue = std::map<std::string, JsonValue>()) const

获取对象引用(安全版本)

参数
defaultValue默认值
返回
对象引用,如果类型不匹配返回默认值

◆ insert() [1/2]

void ast::JsonValue::insert ( const std::string & name,
JsonValue value )

插入键值对

参数
name键名
value键值

◆ insert() [2/2]

template<typename T >
void ast::JsonValue::insert ( const std::string & name,
T value )
inline

插入键值对(模板重载)

参数
name键名
value键值

◆ isArray()

bool ast::JsonValue::isArray ( ) const

判断是否为数组

返回
如果是数组返回 true,否则返回 false

◆ isBool()

bool ast::JsonValue::isBool ( ) const

判断是否为布尔值

返回
如果是布尔值返回 true,否则返回 false

◆ isNull()

bool ast::JsonValue::isNull ( ) const

判断是否为 null 值

返回
如果是 null 值返回 true,否则返回 false

◆ isNumber()

bool ast::JsonValue::isNumber ( ) const

判断是否为数值

返回
如果是数值返回 true,否则返回 false

◆ isObject()

bool ast::JsonValue::isObject ( ) const

判断是否为对象

返回
如果是对象返回 true,否则返回 false

◆ isString()

bool ast::JsonValue::isString ( ) const

判断是否为字符串

返回
如果是字符串返回 true,否则返回 false

◆ operator bool()

ast::JsonValue::operator bool ( ) const

转换为布尔值运算符

返回
布尔值,null 值返回 false,数值非零返回 true,字符串非空返回 true

◆ operator double()

ast::JsonValue::operator double ( ) const

转换为双精度浮点数值运算符

返回
双精度浮点数值,null 值返回 0.0,布尔值 true 返回 1.0,false 返回 0.0,字符串转换为浮点数

◆ operator int()

ast::JsonValue::operator int ( ) const

转换为整数值运算符

返回
整数值,null 值返回 0,布尔值 true 返回 1,false 返回 0,字符串转换为整数

◆ operator std::string()

ast::JsonValue::operator std::string ( ) const

转换为字符串值运算符

返回
字符串值,null 值返回 "null",布尔值返回 "true" 或 "false",数值转换为字符串

◆ operator=() [1/3]

JsonValue & ast::JsonValue::operator= ( const JsonValue & other)

拷贝赋值运算符

参数
other其他 JSON 值
返回
当前 JSON 值的引用

◆ operator=() [2/3]

JsonValue & ast::JsonValue::operator= ( JsonValue && other)
noexcept

移动赋值运算符

参数
other其他 JSON 值
返回
当前 JSON 值的引用

◆ operator=() [3/3]

template<typename T >
JsonValue & ast::JsonValue::operator= ( T value)
inline

赋值运算符(模板重载)

参数
value要赋值的值
返回
当前 JSON 值的引用

◆ operator[]() [1/4]

JsonValue & ast::JsonValue::operator[] ( const std::string & key)

对象下标运算符

参数
key对象键
返回
对应键的 JSON 值引用

◆ operator[]() [2/4]

const JsonValue & ast::JsonValue::operator[] ( const std::string & key) const

对象下标运算符

参数
key对象键
返回
对应键的 JSON 值引用

◆ operator[]() [3/4]

JsonValue & ast::JsonValue::operator[] ( size_t index)

数组下标运算符

参数
index数组索引
返回
对应索引的 JSON 值引用,如果类型不匹配或索引越界返回空值

◆ operator[]() [4/4]

const JsonValue & ast::JsonValue::operator[] ( size_t index) const

数组下标运算符(常量版本)

参数
index数组索引
返回
对应索引的 JSON 值常量引用,如果类型不匹配或索引越界返回空值

◆ parseFromFile()

errc_t ast::JsonValue::parseFromFile ( StringView filepath)

解析 JSON 文件

参数
filepathJSON 文件路径
返回
解析结果

◆ parseFromString()

errc_t ast::JsonValue::parseFromString ( StringView json)

解析 JSON 字符串

参数
jsonJSON 字符串
返回
解析结果

◆ setArray()

void ast::JsonValue::setArray ( const std::vector< JsonValue > & values = {})

设置数组值

参数
valuesJSON 值数组

◆ setBool()

void ast::JsonValue::setBool ( bool value)

设置布尔值

参数
value布尔值

◆ setDouble()

void ast::JsonValue::setDouble ( double value)

设置双精度浮点数值

参数
value双精度浮点数值

◆ setInt()

void ast::JsonValue::setInt ( int value)

设置整数值

参数
value整数值

◆ setObject()

void ast::JsonValue::setObject ( const std::map< std::string, JsonValue > & values = {})

设置对象值

参数
valuesJSON 对象(键值对映射)

◆ setString()

void ast::JsonValue::setString ( StringView value)

设置字符串值

参数
value字符串值

◆ toBool()

bool ast::JsonValue::toBool ( bool defaultValue = false) const

转换为布尔值(安全版本)

参数
defaultValue默认值
返回
布尔值,尝试转换为布尔值,否则返回默认值

◆ toDouble()

double ast::JsonValue::toDouble ( double defaultValue = 0.0) const

转换为双精度浮点数值(安全版本)

参数
defaultValue默认值
返回
双精度浮点数值,尝试转换为浮点数,否则返回默认值

◆ toInt()

int ast::JsonValue::toInt ( int defaultValue = 0) const

转换为整数值(安全版本)

参数
defaultValue默认值
返回
整数值,尝试转换为整数,否则返回默认值

◆ toJsonString()

std::string ast::JsonValue::toJsonString ( int indent = 0) const

转换为 JSON 字符串表示

返回
JSON 值的字符串表示

◆ toString()

std::string ast::JsonValue::toString ( StringView defaultValue = StringView()) const

转换为字符串值(安全版本)

参数
defaultValue默认值
返回
字符串值,尝试转换为字符串,否则返回默认值

◆ type()

EJsonValueType ast::JsonValue::type ( ) const

获取值类型

返回
JSON 值类型

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