stop automatically sorting
rdwong opened this issue · 4 comments
rdwong commented
Hi team, thanks for keeping this addon updated and easy to use.
Just wanted to flag that I've run into an issue where my JSON objects are ALWAYS sorted (alphabetically or by value) the moment I open the raw string with ofxJSONElement, while I need them to remain in the order in the raw string.
At the moment, I'm manually re-ordering them, but perhaps there's an easy way to stop this from happening?
Cheers!
Here's some example code:
ofxJSONElement json;
json.parse( "{ \"charlie\":4, \"alpha\":0.876, \"delta\":\"someString\", \"beta\":123 }" );
cout << json.getRawString();
// prints {"alpha":0.876,"beta":123,"charlie":4,"delta":"someString"}
bakercp commented
This is due to the underlying library, jsoncpp. Additionally, order is not defined in the JSON Object spec
An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).
bakercp commented
If you require an order, you will need to keep track of the order in some other way.
rdwong commented
Gotchya. Thanks Christopher
bakercp commented
You might, for instance be able to use json Array ...
An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).