Iterate through orderer_json #2628
Answered
by
HamletDuFromage
HamletDuFromage
asked this question in
Q&A
-
Hello, I'm trying to iterate through an ordered_json but can't figure it out. My json looks like so : {
"Firmware 11.0.1": "/Firmware%2011.0.1.zip",
"Firmware 11.0.0": "/Firmware%2011.0.0.zip",
"Firmware 10.2.0": "/Firmware%2010.2.0.zip",
"Firmware 10.1.0": "/Firmware%2010.1.0.zip",
"Firmware 10.0.4": "/Firmware%2010.0.4.zip",
"Firmware 10.0.3": "/Firmware%2010.0.3.zip",
"Firmware 10.0.2": "/Firmware%2010.0.2.zip",
"Firmware 10.0.1": "/Firmware%2010.0.1.zip",
"Firmware 10.0.0": "/Firmware%2010.0.0.zip",
"Firmware 9.2.0": "/Firmware%209.2.0.zip",
"Firmware 2.2.0": "/Firmware%202.2.0.zip",
"Firmware 2.1.0": "/Firmware%202.1.0.zip",
"Firmware 2.0.0": "/Firmware%202.0.0.zip",
"Firmware 1.0.0": "/Firmware%201.0.0.zip"
} here's what I do json firmwares = nlohmann::ordered_json::parse(json_str);
for (auto it = firmwares.begin(); it != firmwares.end(); ++it) {
std::cout << it.key() << " | " << it.value() << std::endl;
} but it orders the keys alphabetically. Is there a way to preserve the order when iterating? |
Beta Was this translation helpful? Give feedback.
Answered by
HamletDuFromage
Feb 8, 2021
Replies: 1 comment 4 replies
-
nevermind, of course I need to declare |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
HamletDuFromage
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nevermind, of course I need to declare
nlohmann::ordered_json firmwares
instead ofnlohmann::json firmwares