欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

[C++][第三方库][jsoncpp]详解

最编程 2024-10-06 09:45:36
...
// Json数据对象类 -> 用于进行中间数据存储 class Json::Value { // Value重载了[]和=,因此所有的赋值和获取数据都可以通过[]实现 Value &operator=(const Value &other); // 简单的方式完成 val["姓名"] = "SnowK"; Value& operator[](const std::string& key); Value& operator[](const char* key); // 移除元素 Value removeMember(const char* key); // val["成绩"][0] const Value& operator[](ArrayIndex index) const; // 添加数组元素val["成绩"].append(88); Value& append(const Value& value); // 获取数组元素个数 val["成绩"].size(); ArrayIndex size() const; // 转string string name = val["name"].asString(); std::string asString() const; // 转char* char *name = val["name"].asCString(); const char* asCString() const; // 转int int age = val["age"].asInt(); int asInt() const; // 转float float asFloat() const; // 转 bool bool asBool() const; }; //json序列化类,低版本用这个更简单 class JSON_API Writer { virtual std::string write(const Value& root) = 0; } class JSON_API FastWriter : public Writer { virtual std::string write(const Value& root); } class JSON_API StyledWriter : public Writer { virtual std::string write(const Value& root); } //json 序列化类,高版本推荐,如果用低版本的接口可能会有警告 class JSON_API StreamWriter { virtual int write(Value const& root, std::ostream* sout) = 0; } class JSON_API StreamWriterBuilder : public StreamWriter::Factory { virtual StreamWriter* newStreamWriter() const; } // json反序列化类,低版本用起来更简单 class JSON_API Reader { bool parse(const std::string& document, Value& root, bool collectComments = true); } // json反序列化类,高版本更推荐 class JSON_API CharReader { virtual bool parse(char const* beginDoc, char const* endDoc, Value* root, std::string* errs) = 0; } class JSON_API CharReaderBuilder : public CharReader::Factory { virtual CharReader* newCharReader() const; }