Android Question How to create Map

Calvin Yee

Member
Licensed User
I would like to create a map as per below.

All data is from sqlite. No hardcode on it.

Please advice.


{ "AdminGateWebLink":"http://qa.app.opengatebr.com/CompanyGate",
"AdminUserWebLink":"http://qa.app.opengatebr.com/User",
"ECommerceLink":"http://www.opengatebr.com/#!loja-e-carrinho/cq49",
"GateList": [
{"Id":102,"Name":"as","Url":"21321","Latitude":0,"Longitude":0},
{"Id":105,"Name":"olabug","Url":"189.54.67.252","Latitude":0,"Longitude":0},
{"Id":106,"Name":"pteste01","Url":"189.54.64.75","Latitude":0,"Longitude":0}
]
}
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not a map. It is a json string.

Something like:
B4X:
Dim jg As JsonGenerator
Dim m As Map = CreateMap("AdminGateWebLink": "http://....", "AdminUserWebLink": "http://...", _
   "GateList": Array (CreateMap("Id": 102, ...), _
 CreateMap("Id": 105, ...)))
jg.Initialize(m)
log(jg.ToPrettyString(4))
 
Upvote 0

Calvin Yee

Member
Licensed User
"GateList": Array (CreateMap("Id": 102, ...), _
CreateMap("Id": 105, ...)))


For the GateList: this is a dynamics data will get from table. How to write the coding?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
dim m as map
m.initialize
m.put("Key","Value")
....
 
Upvote 0

Calvin Yee

Member
Licensed User
this is my code:-
I want 2 rows of "properties". system only show 1 row.
Its only display one row.

Please advise.
B4X:
Dim GroupMap As Map
    GroupMap.Initialize
    GroupMap.Put("AdminGateWebLink","http://qa.app.opengatebr.com/CompanyGate")
    GroupMap.Put("AdminUserWebLink","http://qa.app.opengatebr.com/User")
    For i = 0 To 1
        GroupMap.Put("properties",Array( CreateMap("name": i,"IC":i)))
    Next
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize(GroupMap)
    Dim JSONstring As String
    JSONstring = JSONGenerator.ToString
    Log(JSONstring)
Running above coding and show following output:-
{"AdminGateWebLink":"http:\/\/qa.app.opengatebr.com\/CompanyGate","AdminUserWebLink":"http:\/\/qa.app.opengatebr.com\/User","properties":[{"name":1,"IC":1}]}
 
Last edited:
Upvote 0

Calvin Yee

Member
Licensed User
Thank Erel for advise.
I tested following

B4X:
Dim GroupMap As Map
    GroupMap.Initialize
    GroupMap.Put("AdminGateWebLink","http://qa.app.opengatebr.com/CompanyGate")
    GroupMap.Put("AdminUserWebLink","http://qa.app.opengatebr.com/User")
    For i = 0 To 1
        GroupMap.Put("properties",Array( CreateMap("name": i,"IC":i)))
    Next
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize(GroupMap)
    Dim JSONstring As String
    JSONstring = JSONGenerator.ToString
    Log(JSONstring)
Running above coding and show following output:-
{"AdminGateWebLink":"http:\/\/qa.app.opengatebr.com\/CompanyGate","AdminUserWebLink":"http:\/\/qa.app.opengatebr.com\/User","properties":[{"name":1,"IC":1}]}
 
Upvote 0

Similar Threads

Top