JsonCpp如何判断是否有某个KEY

文章出自:http://blog.csdn.net/yannanxiu/article/details/52415640
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;

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

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

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值