JsonCpp如何判断是否有某个KEY

来源:互联网 发布:node buffer 编辑:程序博客网 时间:2024/05/22 13:27


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 );// 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;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

例如要判断Json数据中是否有{“status”:”1”}数据,则可以

if(json["staus"].isString()){    string temp = json["staus"].asCString();}
  • 1
  • 2
  • 3

如果Json中没有status键就不会提取该数据。

原创粉丝点击