wxJSON unordered output
Posted: Mon Mar 02, 2015 11:28 pm
Hi, I am experimenting with wxJSON and I have the problem that in the JSON output file the data isn't in the order I would expect to be.
This is my code:
this is the JSON file content:
and this is the JSON file content I would expect to be:
unfortunately in my application the order in JSON file is very important.
Any idea about this problem?
This is my code:
Code: Select all
TEST(wxJSONTestGroup, wxJSON_Write_File_Test)
{
wxFile file("AppWrData.json", wxFile::write_append);
wxFileStream outStream("AppWrData.json");
// construct the JSON value object and add values to it
wxJSONValue root;
root["MicroNet"]["Description"] = wxString("Application Data File");
root["MicroNet"]["Version"] = wxString("3.0.0");
root["CONST TYPS xTyps"][0]["strFmt"] = wxString("s8h");
root["CONST TYPS xTyps"][0]["wTypSize"] = wxString("10");
root["CONST TYPS xTyps"][0]["wNameIx"] = wxString("0");
root["CONST TYPS xTyps"][1]["strFmt"] = wxString("s21s21");
root["CONST TYPS xTyps"][1]["wTypSize"] = wxString("42");
root["CONST TYPS xTyps"][1]["wNameIx"] = wxString("1");
root["CONST TYPS xTyps"][2]["strFmt"] = wxString("s8");
root["CONST TYPS xTyps"][2]["wTypSize"] = wxString("10");
root["CONST TYPS xTyps"][2]["wNameIx"] = wxString("2");
// construct a JSON writer: use the default writer's settings
// wxJSONWriter writer( wxJSONWRITER_STYLED, 0, 4);
wxJSONWriter writer;
writer.Write(root, outStream);
}
//------------------------------------------------------------------------
Code: Select all
{
"CONST TYPS xTyps" : [
{
"wTypSize" : "10",
"wNameIx" : "0",
"strFmt" : "s8h"
},
{
"wTypSize" : "42",
"wNameIx" : "1",
"strFmt" : "s21s21"
},
{
"wTypSize" : "10",
"wNameIx" : "2",
"strFmt" : "s8"
}
],
"MicroNet" : {
"Description" : "Application Data File",
"Version" : "3.0.0"
}
}
Code: Select all
{
"MicroNet" : {
"Description" : "Application Data File",
"Version" : "3.0.0"
}
"CONST TYPS xTyps" : [
{
"strFmt" : "s8h"
"wTypSize" : "10",
"wNameIx" : "0",
},
{
"strFmt" : "s21s21"
"wTypSize" : "42",
"wNameIx" : "1",
},
{
"strFmt" : "s8"
"wTypSize" : "10",
"wNameIx" : "2",
}
],
}
Any idea about this problem?