C Calvin Yee Member Licensed User Jan 23, 2019 #1 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} ] }
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 Jan 23, 2019 #2 This is not a map. It is a json string. Something like: Code: Copy 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
This is not a map. It is a json string. Something like: Code: Copy 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))
C Calvin Yee Member Licensed User Jan 23, 2019 #3 "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
"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?
DonManfred Expert Licensed User Longtime User Jan 23, 2019 #4 Code: Copy dim m as map m.initialize m.put("Key","Value") .... Upvote 0
C Calvin Yee Member Licensed User Jan 23, 2019 #5 this is my code:- I want 2 rows of "properties". system only show 1 row. Its only display one row. Please advise. Code: Copy 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: Jan 23, 2019 Upvote 0
this is my code:- I want 2 rows of "properties". system only show 1 row. Its only display one row. Please advise. Code: Copy 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}]}
Erel B4X founder Staff member Licensed User Longtime User Jan 23, 2019 #6 Please use [code]code here...[/code] tags when posting code. Upvote 0
C Calvin Yee Member Licensed User Jan 23, 2019 #7 Any idea for my question array don't want hardcoded. How to do it? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jan 23, 2019 #8 You should edit your post and add code tags. Exactly like we made that effort when trying to help you. Upvote 0
You should edit your post and add code tags. Exactly like we made that effort when trying to help you.
C Calvin Yee Member Licensed User Jan 23, 2019 #9 Thank Erel for advise. I tested following Code: Copy 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
Thank Erel for advise. I tested following Code: Copy 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}]}
Erel B4X founder Staff member Licensed User Longtime User Jan 23, 2019 #10 It is critical for developers to understand how the Map collection works. I recommend you to watch the collections video tutorial: https://b4x.com/etp.html Code: Copy Dim names As List names.Initialize For i = 0 To 1 names.Add(CreateMap("name": i,"IC":i)) Next GroupMap.Put("properties", names) Upvote 0
It is critical for developers to understand how the Map collection works. I recommend you to watch the collections video tutorial: https://b4x.com/etp.html Code: Copy Dim names As List names.Initialize For i = 0 To 1 names.Add(CreateMap("name": i,"IC":i)) Next GroupMap.Put("properties", names)
C Calvin Yee Member Licensed User Jan 25, 2019 #11 Hi Erel, Thank you for your help. Solved. Upvote 0