0

I'm going through a json file with the following code:

for (itr = root.begin(); itr != root.end(); itr++){ cout<< "Key: "<<itr.key().toStyledString() << endl;}

I found all the memmbers of the object but at the end the program crash. I think iterator try to move outside the end of the object, but I am not sure. I found this piece of code in many examples so I think it should work fine. Where is my error? This is the file I'm tring to read:

{"lon": [10.6635,10.664510],"lat": [44.144,44.1450101],"range": [0,10.1010101,20.2020202]}
Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
Ros
  • 37
  • 1
  • 6

1 Answers1

1

This complete code example works fine for me:

Json::Value root(Json::objectValue);
Json::Reader reader;
reader.parse("{\"lon\": [10.6635,10.664510],\"lat\": [44.144,44.1450101],\"range\": [0,10.1010101,20.2020202]}", root, false);

std::string output;
for (Json::ValueIterator itr = root.begin(); itr != root.end(); itr++)
    output += "Key: " + itr.key().toStyledString();
Sga
  • 3,608
  • 2
  • 36
  • 47