JSON Parsing

dr3d

New Member
Licensed User
Longtime User
Simple bit of code:

B4X:
Dim s As String
s = "[{ 'nid': '91', 'url': '/api/node/91' }, { 'nid': '92', 'url': '/api/node/92' }]"

Dim parser As JSONParser
parser.Initialize(s)
Try
    Dim l As List
    l = parser.NextObject
Catch
    Log(LastException.Message)
End Try
When I run I get

B4X:
org.json.JSONException: End of input at character 80 of [{ 'nid': '91', 'url': '/api/node/91' }, { 'nid': '92', 'url': '/api/node/92' }]

any ideas ?


EDIT: Apparently if I wrap the JSON string as a object, I can make some progress:

B4X:
parser.Initialize("{data" & s & "}")
Dim m As Map
m = parser.NextObject
Dim l As List
l = m.Get("data")
'etc

Tho I really think the original string is valid JSON and should parse properly...
 
Last edited:

dr3d

New Member
Licensed User
Longtime User
Argh appreciate you taking the time to answer my dopey q.
I confused myself - shoulda saw this...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…