Android Question Create JSON String

Rusty

Well-Known Member
Licensed User
Longtime User
Parsing a JSON string is demonstrated very well in Erel's Tutorial.
I would like to create JSON strings from my data.
Here is an example that I cannot get to work, obviously there are some errors, but I don't see them...
B4X:
    'generate JSON
    Dim Map1 As Map
    Map1.Initialize
    Dim JSONGenerator As JSONGenerator
    Dim Data As List
    Data.Initialize
    Data.Add("Version: 1.1")
    For i = 0 To 30
        Map1.Put(i, "value " & i)
    Next
    Data.Add(Map1)
    JSONGenerator.Initialize(Data)

The above code generates the following error:
Advice is always appreciated
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks KMatle
For those curious:
Add a LIST:
B4X:
    'generate JSON
    Dim Map1 As Map
    Map1.Initialize
    Dim JSONGenerator As JSONGenerator
    Dim Data As List
    Data.Initialize
    Map1.put("Version:","1.1")
    For i = 0 To 30
        Map1.Put(i, "value " & i)
    Next
    Data.Add(Map1)
    JSONGenerator.Initialize2(Data)

Add MAPS:
B4X:
    'generate JSON
    Dim Map1 As Map
    Map1.Initialize
    Dim JSONGenerator As JSONGenerator
    Map1.put("Version:","1.1")
    For i = 0 To 30
        Map1.Put(i, "value " & i)
    Next
    JSONGenerator.Initialize(Map1)
Thanks for your help!
Rusty
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…