Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Determine if JSONNode is object or not

David
2012-11-07
2013-06-12
  • David
    David
    2012-11-07

    Hey, I am switching over from JsonCpp to this library, but have run into a issue. JsonCpp had handy functions like isString(), isInt(), isDouble() and isObject() to determine the type of json value.

    This is causing issues with the following data:

    [code
    ]{
    "type" : "parameter",
    "component" : {
    "name" : "sort",
    "value" : 23
    },
    "drawable" : {}
    }

    Previously, we would use isObject() to determine is the current value type is an object. So with the above json data, isObject would return true for component and drawable, but would return false for type (as type is a string value, not an object).

    Is there some way of doing  this with libjson? One way I was thinking was checking the size of each JSONNode, as the size for "type" JSONNode would return 0, however it would also return 0 for drawable, and therefore would fail the test.

    I'm not sure how to get around this problem, any suggestions would be greatly appreciated!

     
  • David
    David
    2012-11-07

    Ah silly me, calling type() returns if it is a JSON_STRING (which "type" is in the above json), or one of the other types such as JSON_NODE.

     
  • JSON_NODE is the object type.