0
我想使用wxJSON,這是一個包含示例數據在正確的形式,我需要我的簡單測試功能(可惜在我的應用程序以便事項):wxJSON輸出文件的行排列方式不同於預期
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);
}
//------------------------------------------------------------------------
這是JSON輸出它使:
{
"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"
}
}
,這是輸出I想有:
{
"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"
}
],
}
有什麼想法?在我看來,輸出是按字母順序排列的,所以我希望可以禁用輸出順序,但我不明白如何使其可用。