I'm trying to put the contents of map(s) into JSON
Map 1 - m1 goes in as I would expect. Map2 - m2 is only inserting the last element in the map. I looked at the JSON tutorial but I can't seem to figure out the correct code. Your help is appreciated. Thanks, JD.
B4X:
Dim m1 As Map
m1.Initialize
m1.Put("email", "some_email@bestmail.com")
m1.Put("deviceid", "4444444")
Dim m2 As Map
m2.Initialize
m2.Put("id", "AST")
m2.Put("name", "Australia")
m2.Put("id", "EQD")
m2.Put("name", "Equador")
m2.Put("id", "MEX")
m2.Put("name", "Mexico")
Dim Data As List
Data.Initialize
Data.Add(1)
Data.Add(3)
Data.Add(m1)
'or...not working...only shows last map entry: id:MEX, name:Mexico
Data.Add(m2)
'this doesn't work either
Data.Add(m2.GetKeyAt(0))
Data.Add(m2.GetValueAt(0))
'generate JSON
Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize2(Data)
Dim target_json As String
target_json = "'[1,3,{email:some_email@bestmail.com,deviceid:1234567},{id:AST,name:Australia},{id:EQD,name:Equador},{id:MEX,name:Mexico}]'"
Msgbox("target_json: " & target_json ,"")
Msgbox("JSONGenerator: " & JSONGenerator.ToString,"")
Msgbox("stop","")
ExecuteRemoteQuery2(JSONGenerator.ToString, JSON_INSERT)
Map 1 - m1 goes in as I would expect. Map2 - m2 is only inserting the last element in the map. I looked at the JSON tutorial but I can't seem to figure out the correct code. Your help is appreciated. Thanks, JD.