I’m trying to make JSON data with parent and several kids structure.
One parent would have one or several kids, and the number of kids are not fixed. Actually, I think I should make a method to add kids to their parents.
With below code, I see weird result.
Dim root as new JSONItem
Dim finalString As String
Dim Parent as new JSONItem
Parent.Value("H") = "source"
Parent.Value("P") = "2"
Parent.Value("IP") = "192.168.3.3"
Parent.Value("V") = "8"
// first kids
dim KidsArray as new JSONItem( "[]" )
Dim Kids as new JSONItem
Kids.Value("H") = "target1"
Kids.Value("P") = "2"
Kids.Value("IP") = "192.168.3.4"
Kids.Value("V") = "8"
kidsArray.append Kids
Parent.Value("Parents") = KidsArray
root.append Parent
// seconds kids...
dim KidsArray2 as new JSONItem( "[]" )
Dim Kids2 as new JSONItem
Kids2.Value("H") = "target2"
Kids2.Value("P") = "2"
Kids2.Value("IP") = "192.168.3.5"
Kids2.Value("V") = "8"
kidsArray2.append Kids2
Parent.Value("Parents") = KidsArray2
root.append Parent
[{"H":"source","P":"2","IP":"192.168.3.3","V":"8","Parents":[{"H":"target2","P":"2","IP":"192.168.3.5","V":"8"}]},
{"H":"source","P":"2","IP":"192.168.3.3","V":"8","Parents":[{"H":"target2","P":"2","IP":"192.168.3.5","V":"8"}]}]
It should be like below.
[{"H":"source","P":"2","IP":"192.168.3.3","V":"8","Parents":[{"H":"target1","P":"2","IP":"192.168.3.4","V":"8"}]},
"Parents":[{"H":"target2","P":"2","IP":"192.168.3.5","V":"8"}]}]
Can you point me which part is wrong?