0

My JSON file looks like this:

{
"strings": {
    "keyone": "abc",
    "keytwo": "def",
    }
}

Using C++,

const Json::Value strings = root["strings"];
for (int index = 0; index < strings.size(); index++) 
{
    std::cout << strings.isArray() << std::endl;
    std::cout << strings.get(index, "ERROR") << std::endl;
}

strings.IsArray() returns 0, saying it's not an array. And the second line strings.get(index, "ERROR)", just crashes when executing, probably because I'm using it like an array when it's not.

So I'm assuming strings is just a string and not an array. How can I make it an array object?

3
  • 1
    What JSON library are you using? Commented Jul 7, 2012 at 2:11
  • 2
    Why doesn't the JSON above contain a JSON-Array? JSON types (Array, Object, String, etc) are all distinct and do not "share" an ancestor (unlike JavaScript Arrays and JavaScript Objects). Most implementations tend to thus not allow a JSON-Object to be treated as a JSON-Array (and doing so would actually violate the JSON guarantees of such structures). Commented Jul 7, 2012 at 2:21
  • @AndréCaron I am using JsonCpp. Commented Jul 7, 2012 at 2:24

1 Answer 1

3

"strings.IsArray()" returns 0, saying it's not an array

Of course it does, "strings":{ ... } is an "object" in JSON terms.

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

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.