hi
i am trying to create a JSON string and the order of the output string is different than how I have created it.
obviously, it is my mistake but can someone tell me what I am doing wrong?
output:
i am trying to create a JSON string and the order of the output string is different than how I have created it.
obviously, it is my mistake but can someone tell me what I am doing wrong?
B4X:
Sub jsonTry
Dim js As JSONGenerator
js.Initialize(CreateMap("fatherName":"ilan","motherName":"rachel","kids":CreateMap("kid1":"noi","kid2":"moria","kid3":"daniel","kid4":"nehorai"),"adress":"haifa","hobbies":CreateMap("parents":CreateMap("hob1":"sleep","hob2":"watching tv"),"kids":CreateMap("hob1":"xbox","hob2":"annoy parents"))))
Log(js.ToPrettyString(0))
Dim JSON As JSONParser
Dim Map1 As Map
JSON.Initialize(js.ToPrettyString(0)) 'Read the text from a file.
Map1 = JSON.NextObject
Log("###########")
recursiveMapReader(Map1)
End Sub
Sub recursiveMapReader(m As Map)
For Each key As String In m.Keys
If m.Get(key) Is Map Then
Log($"${key} : isMap"$)
recursiveMapReader(m.Get(key))
Else
Log($"${key} : ${m.Get(key)}"$)
End If
Next
End Sub
output:
Waiting for debugger to connect...
Program started.
{
"fatherName": "ilan",
"hobbies": {
"parents": {
"hob1": "sleep",
"hob2": "watching tv"
},
"kids": {
"hob1": "xbox",
"hob2": "annoy parents"
}
},
"motherName": "rachel",
"adress": "haifa",
"kids": {
"kid1": "noi",
"kid4": "nehorai",
"kid2": "moria",
"kid3": "daniel"
}
}
###########
fatherName : ilan
hobbies : isMap
parents : isMap
hob1 : sleep
hob2 : watching tv
kids : isMap
hob1 : xbox
hob2 : annoy parents
motherName : rachel
adress : haifa
kids : isMap
kid1 : noi
kid4 : nehorai
kid2 : moria
kid3 : daniel