Im using jsoncpp , its great but when i need to check if json structure contains tag
when i do it with :
UserRoot0["error"].isNull()
its throws me assert from json_value.cpp line 1025
JSON_ASSERT( type_ == nullValue || type_ == objectValue );
i want to check if response im getting is from this type:
{
"error" : {
"message" : "Error validating application.",
"type" : "OAuthException",
"code" : 190
}
}
The
[]operator is only valid forJsonValueobjects that are of typeObjector null. All others (Int,Bool,Array, etc.) will assert.If your
UserRoot0object is anArrayor some other non-Objecttype, you have some more work to do (like iterating into sub-nodes) to find your target node that may or may not contain the error. PrintUserRoot0.toStyledString()to see what your JSON looks like, and make sure it looks like a JSON Object (see json.org for a nice overview of what that is).A “ToDo” comment at the top of the json_value.cpp source file (where
JSON_ASSERTis defined) implies that the developers may be planning more robust error handling instead of these asserts in future versions, but in the meantime, you can check yourself, like this:The
isMember()check will also assert for non-Objectnodes, so be sure to checkisObject()before checkingisMember()ifUserRoot0isn’t guaranteed to be anObject.