Android Question JSONParser NextArray error with Spaces

alcaraz73

Member
Hi,

I'm having problems reading an array from a Web Service if there are spaces in the data.

B4X:
                    Dim parser As JSONParser
                    parser.Initialize(resultado.Get("Queue"))
                    CPQueueList = parser.NextArray

For example:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:eek:="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2023-09-21T21:28:05.187Z</u:Created><u:Expires>2023-09-21T21:33:05.187Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><QueueCortinaResponse xmlns="http://tempuri.org/"><QueueCortinaResult>{"error":"","Queue":[{"Test":"NoError"}]}</QueueCortinaResult></QueueCortinaResponse></s:Body></s:Envelope>

Works fine, but:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:eek:="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2023-09-21T21:28:44.032Z</u:Created><u:Expires>2023-09-21T21:33:44.032Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><QueueCortinaResponse xmlns="http://tempuri.org/"><QueueCortinaResult>{"error":"","Queue":[{"Test":"With Error"}]}</QueueCortinaResult></QueueCortinaResponse></s:Body></s:Envelope>

throws

org.json.JSONException: Unterminated object at character 13 of [{Test=With Error}]


Thanks in advance
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Are you sure that this line is correct ?
B4X:
 parser.Initialize(resultado.Get("Queue"))

Please tell us what is in this variable:
B4X:
Dim var As String = resultado.Get("Queue")
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
First you need to process the XML to retrieve ONLY the value of queue which should be like this

B4X:
{"error":"","Queue":[{"Test":"With Error"}]}

Next you use the Json Parser to get the error value

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim error As String = jRoot.Get("error")
Dim Queue As List = jRoot.Get("Queue")
For Each colQueue As Map In Queue
 Dim Test As String = colQueue.Get("Test")
Next
 
Last edited:
Upvote 0

alcaraz73

Member
Thanks everybody,

B4X:
Dim Queue As List = jRoot.Get("Queue")

this was the solution, jRoot.Get("Queue") is already a list, not the string value with list elements.

So parser.NextArray throws an error if it was initialized using a list (only if it has spaces).


Regards
 
Upvote 0
Top