0

This is the schema:

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

} I want to read members in "type"

I tried to attempt in many ways, e.g.

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)

3
  • 1
    Count is written using an uppercase C in your JSON and lowercase c in your code - is that intentional? Commented Jan 11, 2018 at 7:55
  • "Count" vs "count" Commented Jan 11, 2018 at 7:55
  • That is mistake while drafting here. Sorry, Now I have modified here. Commented Jan 11, 2018 at 8:01

2 Answers 2

0

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"
                ]
            }
        }
    }
}

;-)

Sign up to request clarification or add additional context in comments.

3 Comments

Actually the JSON code presented here is part of some valid JSON schema (DMTF Redfish schemas). The issue is with code itself.
Change the JSON, try it by yourself... remove the commas and put quotes. It will start to work.
That is what I dont understand...everything seems correct....but it was showing the error.
0
 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;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.