Android Question Error parsing JSON list with Http2

mrjaw

Active Member
Licensed User
Longtime User
Hi!
I am having problem parsing a JSON from webservice , the ws return this
[[17,"clie12345","Chila Perez","-"],[18,"client1235778","Carlos Fuentes","Santiago"]]

B4X:
Log("Response from server: " & res)
                Dim parser As JSONParser
                '
                'res=[[17,"clie12345","Chila Perez","-"],[18,"client1235778","Carlos Fuentes","Santiago"]]

                parser.Initialize(res)
           
                '
                Dim LISTA As List
                LISTA = parser.NextArray 'returns a list with maps
                For i = 0 To LISTA.Size - 1
                    Dim m As Map
                    m = LISTA.Get(i)
                    '===============CREANDO UNA LINEA EN LA TABLA 
                    '-----Agregando a la tabla-------
                    ID =  m.Get("0") & CRLF & m.Get("1") 'ID record; ID empresa
                    Name = m.Get("2") & CRLF & m.Get("3") 'Nombre y direccion
                    TblClientes.AddRow(Array As String(ID, Name))
                Next
This give me an error:

LISTA = parser.NextArray 'returns a list with maps
org.json.JSONException: End of input at character 0 of
at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
at org.json.JSONTokener.nextValue(JSONTokener.java:93)
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:57)
at b4a.example.clientes._jobdone(clientes.java:463)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:930)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
org.json.JSONException: End of input at character 0 of

I took this example from MySQL example with Http2
 

sorex

Expert
Licensed User
Longtime User
just tried it here and it works with that small mod and the res string. but the error you give in the post seems to come from an empty http response.
 
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
No, I took this output from log so it doenst come empty. I check this example from a tutorial of JSON
 
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
This is the example that I took
B4X:
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    Dim res As String
        res = Job.GetString

        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
       
        Select Job.JobName
            Case COUNTRIES_LIST
                Dim COUNTRIES As List
                COUNTRIES = parser.NextArray 'returns a list with maps
                For i = 0 To COUNTRIES.Size - 1
                    Dim m As Map
                    m = COUNTRIES.Get(i)
                    'We are using a custom type named TwoLines (declared in Sub Globals).
                    'It allows us to later get the two values when the user presses on an item.
                    Dim tl As TwoLines
                    tl.First = m.Get("id")
                    tl.Second = m.Get("name")
                    ListView1.AddTwoLines2(tl.First, tl.Second, tl)
                Next
 
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
SOlve!!
The problema was the variable res was declared again so it deleted the value so parse worked over a empty res.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…