加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JsonCpp如何判断是否有某个KEY

发布时间:2020-12-16 19:01:42 所属栏目:百科 来源:网络整理
导读:?? JsonCpp如何判断是否有某个KEY,使用json[“key”]和isXXX的函数即可。 如果json中没有key键,则会创建一个空成员或者返回一个空成员。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Access an object value by name,create a null member if it
??

JsonCpp如何判断是否有某个KEY,使用json[“key”]和isXXX的函数即可。
如果json中没有key键,则会创建一个空成员或者返回一个空成员。

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
// 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”}数据,则可以

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读