jsoncpp 常用函数
时间: 2023-10-11 19:09:25 浏览: 40
1. `Json::Value`:表示 JSON 数据的类。它可以表示 JSON 对象、数组、字符串、数字、布尔值和 null 值。它还提供了许多操作 JSON 数据的方法,如读取、修改、序列化和反序列化等。
2. `Json::Reader`:将 JSON 字符串解析为 `Json::Value` 对象的类。它提供了 `parse()` 方法,可以将 JSON 字符串解析为 `Json::Value` 对象。如果解析失败,它会返回 `false`。
3. `Json::FastWriter` 和 `Json::StyledWriter`:将 `Json::Value` 对象序列化为 JSON 字符串的类。`Json::FastWriter` 生成的 JSON 字符串没有缩进和换行,`Json::StyledWriter` 生成的 JSON 字符串有缩进和换行。
4. `Json::Value::operator[]()` 和 `Json::Value::get()`:读取 `Json::Value` 对象中的数据。`Json::Value::operator[]()` 可以通过键名访问 JSON 对象中的数据,`Json::Value::get()` 可以通过键名或者下标访问 JSON 数组中的数据。
5. `Json::Value::append()` 和 `Json::Value::clear()`:向 `Json::Value` 对象中添加数据和清空数据。`Json::Value::append()` 可以向 JSON 数组中添加数据,`Json::Value::clear()` 可以清空 JSON 对象或者数组中的数据。
6. `Json::Value::isNull()` 和 `Json::Value::type()`:判断 `Json::Value` 对象的类型和值是否为 null。`Json::Value::isNull()` 可以判断 `Json::Value` 对象的值是否为 null,`Json::Value::type()` 可以获得 `Json::Value` 对象的类型,如 JSON 对象、数组、字符串、数字、布尔值或者 null 值。
7. `Json::Value::toStyledString()` 和 `Json::Value::asString()`:将 `Json::Value` 对象转换为字符串。`Json::Value::toStyledString()` 可以将 `Json::Value` 对象转换为有缩进和换行的 JSON 字符串,`Json::Value::asString()` 可以将 `Json::Value` 对象转换为没有缩进和换行的 JSON 字符串。
8. `Json::StreamWriterBuilder` 和 `Json::CharReaderBuilder`:自定义 JSON 序列化和反序列化的配置。`Json::StreamWriterBuilder` 可以配置生成的 JSON 字符串是否有缩进和换行,`Json::CharReaderBuilder` 可以配置解析 JSON 字符串时的一些选项,如是否允许注释和特殊字符。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)