Android Question Json format

alimanam3386

Active Member
Licensed User
Longtime User
Hi guys

How can I create like bellow json format by map obj and json lib ?

B4X:
{
    "count": 3 ,
    "result" : 200,
    "message": "OK",
            "data": [
                        {"id": 1 , "name": "A" , "family": "AA"},
                        {"id": 2 , "name": "B" , "family": "BB"} ,
                        {"id": 3 , "name": "C" , "family": "CC"}
            ]
}
 

alimanam3386

Active Member
Licensed User
Longtime User
Thank you eurojam , I want to create json string like json that I showed in my first post. I know this link but I dont have json format yet ! I want create it first and after that I can use your link o_O
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
will be something like (not tested, only written down...):
B4X:
Dim jsonmap As Map
Dim dataList As List
Dim cols As Map
jsonmap.Initialize
dataList.Initialize
Dim maxi = 5

For i = 0 To maxi
  cols.Initialize
  cols.Put("name", "N"&i)
  cols.Put("id", i)
  cols.Put("family", "CC")
  dataList.Add(cols)

Next
jsonmap.put("data", dataList)
jsonmap.put("count", maxi)
jsonmap.Put("message", "OK")
Dim parser As JSONGenerator
parser.Initialize(jsonmap)
Log(parser.ToString)
 
Upvote 0
Top