c++ - jsoncpp how to check if tag is null .isNull() throw assertion -
im using jsoncpp , great when need check if json structure contains tag when :
userroot0["error"].isnull() its throws me assert json_value.cpp line 1025
json_assert( type_ == nullvalue || type_ == objectvalue ); i want check if response im getting type:
{ "error" : { "message" : "error validating application.", "type" : "oauthexception", "code" : 190 } }
the [] operator valid jsonvalue objects of type object or null. others (int, bool, array, etc.) assert.
if userroot0 object array or other non-object type, have more work (like iterating sub-nodes) find target node may or may not contain error. print userroot0.tostyledstring() see json looks like, , make sure looks json object (see json.org nice overview of is).
a "todo" comment @ top of json_value.cpp source file (where json_assert defined) implies developers may planning more robust error handling instead of these asserts in future versions, in meantime, can check yourself, this:
if(userroot0.isobject() && userroot0.ismember("error")) // process error node else // node isn't object node or doesn't contain "error" key the ismember() check assert non-object nodes, sure check isobject() before checking ismember() if userroot0 isn't guaranteed object.
Comments
Post a Comment