You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can function dump() return string in the order I push in the json object ? #286
the program like this:
json obj = { {"result", "OK"}, {"model", "AAA" } };
string str = obj.dump();
which i want get { {"result", "OK"}, {"model", "AAA" } }, but it always return { {"model", "AAA" }, {"result", "OK"} }
This is not possible. JSON objects are, by definition, unordered set of key-value pairs. In the library, I use a std::map to store objects, so the keys are always ordered alphabetically. You may want to try if you use https://github.com/nlohmann/fifo_map as object_t.
Activity
nlohmann commentedon Jul 25, 2016
This is not possible. JSON objects are, by definition, unordered set of key-value pairs. In the library, I use a
std::mapto store objects, so the keys are always ordered alphabetically. You may want to try if you use https://github.com/nlohmann/fifo_map asobject_t.ivakyb commentedon Jan 12, 2018
How to replace
std::mapwithfifo_map?ivakyb commentedon Jan 15, 2018
See https://github.com/nlohmann/json#notes, last item about insertion order of object elements.