iOS Question Error in Parsing JSON (list in a map)

hatzisn

Expert
Licensed User
Longtime User
Hi everyone,

consider the following JSON:

Code: Copy
{"root":[{"VersionID":18,"SelectedVersion":1},{"VersionID":20,"SelectedVersion":2}]}

This JSON cannot be parsed in B4i v5.50.
The first step is concluded successfully but if you try to get the list you 're toasted for good (check the attached project). Any ideas anyone?

Thanks in advance
 

Attachments

Looks like correct JSON and works without problems
Code: Copy
    Dim sJSON As String = $"{"root":[{"VersionID":18,"SelectedVersion":1},{"VersionID":20,"SelectedVersion":2}]}"$
   
    Dim parser As JSONParser
    parser.Initialize (sJSON)   
    Dim map As Map = parser.NextObject
    Dim list As List = map.Get("root")
    For Each colroot As Map In list
        Log ("SelectedVersion = " & colroot.Get ("SelectedVersion"))
        Log ("VersionID = " & colroot.Get ("VersionID"))
    Next
 
Upvote 0
I do not understand. The code by Semen works with me too. My code in the attached project does not work in b4i but works perfect in b4a as it is copied from the same project in b4a which works.
 
Upvote 0
Nothing strange. Your assign List to String in
Code: Copy
sJSON = m.Get("root")
Very doubt that there is a standard for similar conversion. Anyway, no reason to expect the same results in B4I and in B4A.

BTW, your code is very redundant. For example, your initialize map/list and then get it from the parser.
And to initialize parser one time is enough.
 
Upvote 0
I don't really consider the code redundant. That is called defensive programming. My moto is "throw and handle exceptions only when you need them".
 
Upvote 0
Back
Top