Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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)

Count is written using an uppercase C in your JSON and lowercase c in your code - is that intentional? – UnholySheep Jan 11, 2018 at 7:55

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" Actually the JSON code presented here is part of some valid JSON schema (DMTF Redfish schemas). The issue is with code itself. – Sundeep Kumar Gorantla Jan 11, 2018 at 8:39 Change the JSON, try it by yourself... remove the commas and put quotes. It will start to work. – Wagner Patriota Jan 11, 2018 at 15:47 That is what I dont understand...everything seems correct....but it was showing the error. – Sundeep Kumar Gorantla Jan 11, 2018 at 15:49
 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;
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.