# jsoncpp
# ubuntu
编译
github
地址:https://github.com/open-source-parsers/jsoncpp/releases解压 (后面跟上你压缩包名称)
tar xzvf jsoncpp-1.9.5.tar.gz
编译
mkdir build
cd build
cmake ..
make
生成的静态库文件和动态库文件在
build/lib
下方one@one-virtual-machine:~/下载/jsoncpp-1.9.5/build/lib$ ls
libjsoncpp.a libjsoncpp.so libjsoncpp.so.1.9.5 libjsoncpp.so.25
将生成的静态库 / 动态库、头文件
./include/json
放置于你的项目目录下
# jsoncpp API
jsoncpp
库中的类被定义在 Json
的命名空间中,使用 jsoncpp
解析 json
格式的数据,常用的一下几个类:
# Value
封装了 jsoncpp
支持解析的数据类型,有如下几种:
nullValue
intValue
uintValue
realValue
stringValue
booleanValue
arrayValue
objectValue
构造函数
成员方法
# FastWriter
将 Value
对象中的数据序列化为字符串
# Reader
将 json
字符串反序列化为 Value
对象
bool Reader::parse(const std::string document, Value& root, bool collectComments = true); // C++ 风格 | |
/* | |
参数: | |
1. document: json 格式的字符串 | |
2. root: 传出参数,保留解析出的数据(存储在 Value 对象中) | |
3. collectComments: 是否保存 json 字符串中的注释信息 | |
*/ | |
bool Reader::parse(const char *beginDoc, const char* endDoc, Value& root, bool collectComments = true); // C 风格 | |
bool Reader::parse(std::istream& is, Value& root, bool collectComments = true); |