JsonCpp如何判断是否有某个KEY



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键就不会提取该数据。

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...