I have a C++ code with an nlohmann::json
array-type object. So it kinda looks like
[{"abc":-0.09275999665260315,"def":-0.06765999644994736,"ghi":0.0010000000474974513},{"abc":-0.0027000000700354576,"def":0.014310000464320183,"ghi":1.5950000286102295}, ...]
Now, I want to loop over these elements. What I have done is basically follow what is written here: https://json.nlohmann.me/api/basic_json/items/, but it does not really seem to work.
My code is (with the json object being called lines
):
std::cout << lines.dump() << std::endl;
std::cout << "size is: "<< lines.size() << std::endl;
for(auto& elm : lines.items()){
++nLines;
nlohmann::json line = elm.value();
std::cout << elm << std::endl;
std::cout << "line: " << line.dump() << std::endl;
...
}
and my output is (truncating after first loop since downstream code crashes):
[{"abc":-0.09275999665260315,"def":-0.06765999644994736,"ghi":0.0010000000474974513},{"abc":-0.0027000000700354576,"def":0.014310000464320183,"ghi":1.5950000286102295}, ...]
size is: 638
{"0":null}
line: null
What am I doing wrong?
Thank you in advance!
conni