I will have a quite huge JSON file in the end, and the idea is to let customers change this file later.
But for this it is important to keep the structure, otherwise the data looks quite chaotic on a first look.
Example code:
Code: Select all
Structure _SLAVE_INFO_
Version.s
Locales.s
Deviceclass.s
Devicename.s
Codenumber.i
Manufacturername.s
Codenumber_Offset.i
PasswordID.i
ServiceName.s
FactoryCode.i
EndStructure
Global NewList Groupnames.s()
Global GL._SLAVE_INFO_
AddElement(Groupnames()) : Groupnames() = "Product ID"
AddElement(Groupnames()) : Groupnames() = "Operation"
AddElement(Groupnames()) : Groupnames() = "Failure"
AddElement(Groupnames()) : Groupnames() = "Measurement Setup"
AddElement(Groupnames()) : Groupnames() = "I/O And Com. Setup"
AddElement(Groupnames()) : Groupnames() = "Service"
AddElement(Groupnames()) : Groupnames() = "Basic Data logger 1"
AddElement(Groupnames()) : Groupnames() = "Basic Data logger 2"
AddElement(Groupnames()) : Groupnames() = "Advanced information"
AddElement(Groupnames()) : Groupnames() = "Option"
Procedure main()
Protected OV, FileInfo, Group, Groups, Languages
If CreateJSON(0)
OV = SetJSONObject(JSONValue(0))
FileInfo = AddJSONMember(OV, "FileInfo")
InsertJSONStructure(FileInfo, @GL, _SLAVE_INFO_)
Groups = AddJSONMember(OV, "Groups")
SetJSONObject(Groups)
ForEach Groupnames()
Group = AddJSONMember(Groups, Groupnames())
Next
Languages = AddJSONMember(OV, "Languages")
Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
FreeJSON(0)
EndIf
EndProcedure
main()
The fileinfo structure order is completely different to my structure _SLAVE_INFO_ and the groupnames order doesn't reflect the order I added them.
I know, that it doesn't make any difference in the end, any JSON parser will be able to parse it successfully.
But the JSON file looks very unstructured and it will be difficult for customers to find the correct groupname and setting.
Is it somehow possible to keep the order?