we are switching Json libaries from JsonCpp to libJson. JsonCpp has nice functions to determine the object type of a json value. Is there any equvialent way of getting this information in libjson?

For example, using JsonCpp we have the following:

Json::Value property = properties[propertyName.get_utf8()];

if (property.isInt()) 
{
    // Do Something
}
else if (property.isUInt())
{
    // Do Something
}
else if (property.isDouble())
{
    // Do Something
}
else if ( property.isString() )
{
    // Do Something
}

Is there any way to determine if a JSONNode has a string, int or double. I know you can get the JSONNode type, but can you get the object type for the value within that node. For example, if I have the following:

JSONNode root(JSON_NODE);
node.push_back(JSONNode("", "node"));
node.push_back(JSONNode("", 10));
node.push_back(JSONNode("", 21.5f));
node.push_back(JSONNode("", true));

Is it possible to determine that the first node in root contains a string, the second an int, the third a float etc?

有帮助吗?

解决方案

Checking the type seems to be the only way of doing this, alright it is not very accurate as you can only check if it is a number, but not if it is an int of a double.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top