Android Question JSON.NextArray

Firpas

Active Member
Licensed User
Longtime User
I've a problem with Json lib when the json string is an emty array

This code :
B4X:
Dim StrResult as string = "[]"
Dim Json As JSONParser
Json.Initialize(StrResult)
Dim Positions As List =  Json.NextArray
cause an error:

Positions = Json.NextArray
org.json.JSONException: End of input at character 2 of []
at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
at org.json.JSONTokener.nextValue(JSONTokener.java:97)
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:60)

Thanks in advance
 

Ohanian

Active Member
Licensed User
Longtime User
Hi
check the data and then parse it or simply just put it in a try catch block.
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
With this Json string also crash:

[{"Telf":"666666666","Icono":"icon01.png","Lat":36.8003,"Lng":-2.5830318927764893,"Mde":"WIFI","Fecha":"20151224"}]

Any idea ???
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize($"[{"Telf":"666666666","Icono":"icon01.png","Lat":36.8003,"Lng":-2.5830318927764893,"Mde":"WIFI","Fecha":"20151224"}]"$)
Dim root As List = parser.NextArray
For Each colroot As Map In root
  Dim Lng As Double = colroot.Get("Lng")
  Dim Fecha As String = colroot.Get("Fecha")
  Dim Icono As String = colroot.Get("Icono")
  Dim Telf As String = colroot.Get("Telf")
  Dim Lat As Double = colroot.Get("Lat")
  Dim Mde As String = colroot.Get("Mde")
Next
 
Upvote 0
Top