Android Question Error convert list to map

mrjaw

Active Member
Licensed User
Longtime User
I am getting an error when I use map with List

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) 'Here this is the error--
                    '========CREANDO UNA LINEA EN LA TABLA VISTA==
                    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

clientes_jobdone (B4A line: 107)

m = LISTA.Get(i)
java.lang.ClassCastException: java.util.ArrayList
at b4a.example.clientes._jobdone(clientes.java:484)
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:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
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:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
 

DonManfred

Expert
Licensed User
Longtime User
I must agree with @thedesolatesoul Usually a valid json-string contains keyvalue-pairs. A name and a Value. Your json-string seems to have just values.

For example this is such an json i talked about:

{"menu": {"id": "file","value": "File","popup": {"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…