JsonCpp如何判断是否有某个KEY
发布时间:2020-12-16 19:34:05 所属栏目:百科 来源:网络整理
导读:JsonCpp如何判断是否有某个KEY,使用json[“key”]和isXXX的函数即可。 如果json中没有key键,则会创建一个空成员或者返回一个空成员。 // Access an object value by name,create a null member if it does not exist. Value operator []( const char *key
JsonCpp如何判断是否有某个KEY,使用json[“key”]和isXXX的函数即可。 // Access an object value by name,create a null member if it does not exist.
Value &operator[]( const char *key );
// Access an object value by name,returns null if there is no member with that name.
const Value &operator[]( const char *key ) const;
// Access an object value by name,create a null member if it does not exist.
Value &operator[]( const std::string &key );
// Access an object value by name,returns null if there is no member with that name.
const Value &operator[]( const std::string &key ) const;
bool isNull() const;
bool isBool() const;
bool isInt() const;
bool isUInt() const;
bool isIntegral() const;
bool isDouble() const;
bool isNumeric() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
例如要判断Json数据中是否有{“status”:”1”}数据,则可以 if(json["staus"].isString()){
string temp = json["staus"].asCString();
}
如果Json中没有status键就不会提取该数据。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |