Android Question JSON.NextArray removes quotes

Azam Memon

Member
Licensed User
Hi,

I am trying to parse a JSON string containing arrays, objects, and arrays inside of objects, but once when I get array, the quotes to parameters are removed.

A sample code is:
B4X:
galaxy.json.Initialize($"[{"id":"23","parameters":{"post_date":"2018-01-21 18:30:10","post_contents":"<img class="size-medium wp-image-24" src="https:\/\/www.islamicinfo.net\/wp\/wp-content\/uploads\/2018\/01\/IMG_20180122_022711-300x116.jpg" alt="" width="300" height="116" \/>","post_title":"Sana","post_excerpt":"","post_status":"publish","post_name":"sana","post_modified":"2018-01-21 18:30:10","post_modified_gmt":"2018-01-21 18:30:10","post_parent":"0","guid":"","post_type":"post","post_mime_type":"","number_attachments":1,"author":"Info786"}}]"$)
           
            Dim list2 As List = galaxy.json.NextArray
            Log("B" & CRLF)
           
            galaxy.json.Initialize(list2.Get(0))
            Log("Next Object: " & galaxy.json.NextObject & CRLF)

After json.NextArray I get:

B4X:
(ArrayList) [{id=23, parameters={post_date=2018-01-21 18:30:10, post_contents=<img class="size-medium wp-image-24" src="https://www.islamicinfo.net/wp/wp-content/uploads/2018/01/IMG_20180122_022711-300x116.jpg" alt="" width="300" height="116" />, post_title=Sana, post_excerpt=, post_status=publish, post_name=sana, post_modified=2018-01-21 18:30:10, post_modified_gmt=2018-01-21 18:30:10, post_parent=0, guid=, post_type=post, post_mime_type=, number_attachments=1, author=Info786}}]

A json string without quotation marks, so when I process the json with this new string, I get error:

B4X:
org.json.JSONException: Unterminated object at character 42 of {id=23, parameters={post_date=2018-01-21 18:30:10, post_contents=<img class="size-medium wp-image-24" src="https://www.islamicinfo.net/wp/wp-content/uploads/2018/01/IMG_20180122_022711-300x116.jpg" alt="" width="300" height="116" />, post_title=Sana, post_excerpt=, post_status=publish, post_name=sana, post_modified=2018-01-21 18:30:10, post_modified_gmt=2018-01-21 18:30:10, post_parent=0, guid=, post_type=post, post_mime_type=, number_attachments=1, author=Info786}}
 

OliverA

Expert
Licensed User
Longtime User
As per JSONParser docs (https://www.b4x.com/android/help/json.html#jsonparser)
JSON objects are converted to Maps and JSON arrays are converted to Lists.
After initializing the object you will usually call NextObject to get a single Map object.
If the JSON string top level value is an array you should call NextArray.
Afterward you should work with the Map or List and fetch the required data.
NextArray returns a B4A list object and you should use B4A list methods to parse from then on. If you need multi-level parsing, you may want to use NextObject and traverse the resulting map object via the various map object methods. If you need help with coding your access to the various JSON structures, use JsonTree (https://www.b4x.com/android/forum/t...help-with-json-parsing-b4a-b4j.35963/#content) to create the boiler plate code for you.
 
Upvote 0
Top