Fixed memory leak issue caused by incorrect deallocation order in the Json_Value destructor && Fixed issue where copy construction of read-only reference members in Json_Value failed to pass && Added read-only reference members for Json_Object and Json_Array && Added const qualifiers to methods that do not modify class members && Implemented JSON file parsing && Implemented JSON file export, supporting minified export and pretty print.
This commit is contained in:
+38
-15
@@ -21,6 +21,23 @@ class Json_Value; // Json 值(可以是数组、对象、字符串、浮点
|
||||
*/
|
||||
std::string JsonFile_FormatCheck(const char *path_to_file);
|
||||
|
||||
/**
|
||||
* @brief 解析Json文件
|
||||
* @param path_to_file 文件路径串
|
||||
* @param pJson_Value Value 指针
|
||||
* @return std::string 错误值
|
||||
*/
|
||||
std::string JsonFile_Parse(const char *path_to_file, Json_Value *pJson_Value);
|
||||
|
||||
/**
|
||||
* @brief Json对象保存
|
||||
* @param path_to_file 文件路径串
|
||||
* @param value Json Value
|
||||
* @param enable_pretty_print 启用美观打印
|
||||
* @return std::string 错误值
|
||||
*/
|
||||
std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_pretty_print = true);
|
||||
|
||||
// Json 数组
|
||||
class Json_Arry
|
||||
{
|
||||
@@ -29,6 +46,9 @@ private:
|
||||
std::vector<Json_Value> private_element_list;
|
||||
|
||||
public:
|
||||
// 只读引用
|
||||
const std::vector<Json_Value> &element_list = this->private_element_list;
|
||||
|
||||
// 默认构造
|
||||
Json_Arry() = default;
|
||||
// 列表构造
|
||||
@@ -38,12 +58,12 @@ public:
|
||||
// 深拷贝
|
||||
Json_Arry &operator=(const Json_Arry &another);
|
||||
// 获取元素大小
|
||||
size_t size(void);
|
||||
size_t size(void) const;
|
||||
// 数组索引重载
|
||||
Json_Value operator[](size_t index);
|
||||
Json_Value operator[](size_t index) const;
|
||||
|
||||
// 是否为空
|
||||
bool isNull(void);
|
||||
bool isNull(void) const;
|
||||
};
|
||||
|
||||
// Json 值定义
|
||||
@@ -92,15 +112,15 @@ public:
|
||||
~Json_Value();
|
||||
|
||||
// 获取值
|
||||
std::string asString(void);
|
||||
Json_Arry asArry(void);
|
||||
Json_Object asObject(void);
|
||||
int64_t asInteger(void);
|
||||
double asFloat(void);
|
||||
bool asBoolean(void);
|
||||
std::string asString(void) const;
|
||||
Json_Arry asArry(void) const;
|
||||
Json_Object asObject(void) const;
|
||||
int64_t asInteger(void) const;
|
||||
double asFloat(void) const;
|
||||
bool asBoolean(void) const;
|
||||
|
||||
// 是否为空
|
||||
bool isNull(void);
|
||||
bool isNull(void) const;
|
||||
};
|
||||
|
||||
// Json 键值对定义
|
||||
@@ -126,7 +146,7 @@ public:
|
||||
Json_Pair &operator=(const Json_Pair &another);
|
||||
|
||||
// 空判定
|
||||
bool isNull();
|
||||
bool isNull() const;
|
||||
};
|
||||
|
||||
// Json 对象
|
||||
@@ -137,6 +157,9 @@ private:
|
||||
std::vector<Json_Pair> private_element_list;
|
||||
|
||||
public:
|
||||
// 只读引用
|
||||
std::vector<Json_Pair> const &element_list = this->private_element_list;
|
||||
|
||||
// 默认构造
|
||||
Json_Object() = default;
|
||||
// 列表构造
|
||||
@@ -147,15 +170,15 @@ public:
|
||||
Json_Object &operator=(const Json_Object &another);
|
||||
|
||||
// 获取元素大小
|
||||
size_t size(void);
|
||||
size_t size(void) const;
|
||||
// 数组索引重载
|
||||
Json_Pair operator[](size_t index);
|
||||
Json_Pair operator[](size_t index) const;
|
||||
|
||||
// 由Key 查找值
|
||||
Json_Value get(std::string key);
|
||||
Json_Value get(std::string key) const;
|
||||
|
||||
// 是否为空
|
||||
bool isNull(void);
|
||||
bool isNull(void) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user