A alcaraz73 Member Sep 21, 2023 #1 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="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="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
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="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="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
aeric Expert Licensed User Longtime User Sep 22, 2023 #2 I wonder why the API provider mixed SOAP XML with JSON. Upvote 0
sirjo66 Well-Known Member Licensed User Longtime User Sep 22, 2023 #3 Are you sure that this line is correct ? Code: parser.Initialize(resultado.Get("Queue")) Please tell us what is in this variable: Code: Dim var As String = resultado.Get("Queue") Upvote 0
Are you sure that this line is correct ? Code: parser.Initialize(resultado.Get("Queue")) Please tell us what is in this variable: Code: Dim var As String = resultado.Get("Queue")
mcqueccu Expert Licensed User Longtime User Sep 22, 2023 #4 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: Sep 22, 2023 Upvote 0
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
mcqueccu Expert Licensed User Longtime User Sep 22, 2023 #5 Try this Attachments xmlJsonTEst.zip xmlJsonTEst.zip 3.3 KB · Views: 405 Upvote 0
A alcaraz73 Member Sep 23, 2023 #6 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
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