简体   繁体   中英

jsoncpp compilation error for Json::Value type

This is the schema:

{
"definitions": {
    "properties": {
        "Count": {
            "type": [
                "number",
                "null"
            ]
        }
    }
}

} I want to read members in "type"

I tried to attempt in many ways, eg

if(val["definitions"]["properties"]["Count"]["type"][0] == "number" and 
(val["definitions"]["properties"]["Count"]["type"][1] == "null"))
{
    //code here
}

This leads to the following error

error : terminate called after throwing an instance of 'Json::LogicError' what(): in Json::Value::operator: requires arrayValue Aborted (core dumped)

And for this piece of code

if (val["definitions"]["properties"]["Count"]["type"][0].isMember("number") and 
(val["definitions"]["properties"]["Count"]["type"][0].isMember("null"))){
    //code here
}

I get

error: terminate called after throwing an instance of 'Json::LogicError' what(): in Json::Value::find(key, end, found): requires objectValue or nullValue Aborted (core dumped)

You code is right... your json is wrong... JsonCpp needs the quotes for "definitions" and you can't have extra commas after the last item in an array or object.

just change it to:

{
    "definitions": {
        "properties": {
            "Count": {
                "type": [
                    "number",
                    "null"
                ]
            }
        }
    }
}

;-)

 const Json::Value obj=val["definitions"]["properties"]["count"]["type"];
    if (std::find(obj.begin(),obj.end(),"string")!=obj.end() and 
 std::find(obj.begin(),obj.end(),"null")!=obj.end()){
    // code here;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM