iOS Question JSON Parse issue

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I have the following JSON message:

B4X:
{"Command":"GetUserServices", "NumOfServices": 2,"UserService": [{"AccountID": "ABC12345", "ServiceName": "Test 1", "ServiceStatus": "pending"},{"AccountID": "ABC98765", "ServiceName": "Test 2", "ServiceStatus": "active"}]}}

I am trying to get the values from the above JSON message in B4i.

I have used the following code.. (Got code from: http://www.b4x.com:51042/json/index.html)
B4X:
Dim value As String = $"{"Command":"GetUserServices", "NumOfServices": 2,"UserService": [{"AccountID": "ABC12345", "ServiceName": "Test 1", "ServiceStatus": "pending"},{"AccountID": "ABC98765", "ServiceName": "Test 2", "ServiceStatus": "active"}]}}"$

    Dim parser As JSONParser
    parser.Initialize(value)
    Dim root As Map = parser.NextObject
    Dim NumOfServices As Int = root.Get("NumOfServices")
    Dim Command As String = root.Get("Command")
    Dim UserService As List = root.Get("UserService")
    For Each colUserService As Map In UserService
        Dim AccountID As String = colUserService.Get("AccountID")
        Dim ServiceName As String = colUserService.Get("ServiceName")
        Dim ServiceStatus As String = colUserService.Get("ServiceStatus")
        Log(ServiceName & " - " & ServiceStatus & " - " & AccountID)
    Next

When I run the above code I am getting the following error:

Line 76 is: Dim root As Map = parser.NextObject

Anyone know what I have done wrong ?

B4i Version: 3.50
Running on Windows 10 on Mac using Parallels desktop
iJSON Lib 1.00
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is an extra '}' character. Format it better and you will see it:
B4X:
  Dim value As String = $"{
     "Command":"GetUserServices", "NumOfServices": 2,
     "UserService": [{"AccountID": "ABC12345", "ServiceName": "Test 1", "ServiceStatus": "pending"},{"AccountID": "ABC98765", "ServiceName": "Test 2", "ServiceStatus": "active"}]
   }}"$
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
There is an extra '}' character. Format it better and you will see it:
Good find. I thought I had looked at that but looks like I overlooked it.
Thanks heaps for your help, it was driving me mad..
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…