wxJSON unordered output

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
micronpn
Earned a small fee
Earned a small fee
Posts: 20
Joined: Wed Feb 25, 2015 4:18 pm

wxJSON unordered output

Postby micronpn » 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:

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);
}
//------------------------------------------------------------------------


this is the JSON file content:

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"
   }
}


and this is the JSON file content I would expect to be:

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",
      }
   ],
}


unfortunately in my application the order in JSON file is very important.

Any idea about this problem?
Last edited by doublemax on Tue Mar 03, 2015 12:43 am, edited 2 times in total.
Reason: Added code tags.

evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2069
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxJSON unordered output

Postby evstevemd » Mon Mar 16, 2015 12:25 pm

AFAIK wxJSon is no longer maintained .... no?
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 1 guest