mbubnjaric
Member
Hi!
I am calling a web service with JSON result. And during JSON parsing my app is behaving strange. Sometimes the call is successuful sometime there is an error:
(ClassCastException) java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
Here is the code and the error is in line 38. It is al little confusing that the error is happening only sometimes. When I add some line, for example log after line 69 then the error is missing. But this appens only in debug mode. In release (obfuscated) mode the error is permanent.
I am calling a web service with JSON result. And during JSON parsing my app is behaving strange. Sometimes the call is successuful sometime there is an error:
(ClassCastException) java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
Here is the code and the error is in line 38. It is al little confusing that the error is happening only sometimes. When I add some line, for example log after line 69 then the error is missing. But this appens only in debug mode. In release (obfuscated) mode the error is permanent.
B4X:
Public Sub CallServisCistoce As ResumableSub
Dim Result As String
Dim URL As String = "https://moja.cistoca-vz.hr/Public/JSONgetRasporedPoKoordinatamaAdresiDrugiPut"
Dim m As Map = CreateMap("IdUlice": "1641", "kbrCijeli": "6", "idSkupine" : "1", "idSKBR" : "65550")
Dim Parameters As String = m.As(JSON).ToString
Log("sistemsko:" & DateTime.Date(DateTime.Now))
Dim format As String = "dd.MM.yyyy"
SetDateFormat("hr", "HR", format)
Dim sada As Long
Dim sada_str As String
sada = DateTime.Now
sada_str = DateTime.Date(DateTime.Now)
Dim j As HttpJob
Try
j.Initialize("", Me)
j.PostString(URL, Parameters)
j.GetRequest.SetContentType("application/json")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Result = j.GetString
Log("Result:" & Result)
Dim parser As JSONParser
parser.Initialize(Result)
Dim jRoot As Map = parser.NextObject
Dim ListaOtpada As List
ListaOtpada.Initialize
ListaOtpada = jRoot.Get("dtRaspored")
For Each m As Map In ListaOtpada.As(JSON).ToList
DateTime.DateFormat = "yyyy-MM-dd"
Dim t As Long
Dim datum1 As String
datum1 = m.Get("datum")
datum1 = datum1.SubString2(0,10)
t = DateTime.DateParse(datum1)
'Log("t:" &t)
DateTime.DateFormat = "dd.MM.yyyy"
Dim s As String
s = DateTime.Date(t)
m.Put("startTime",t)
If t >= sada Then
'Log("redak" & m.Get("datum") & " " & m.Get("nazivTipa") & "startTime:" & m.Get("startTime"))
'Log("s:" & s)
Dim otp As Otpad
otp.datum = s
otp.datumInt = m.Get("startTime")
otp.spremnik = m.Get("nazivTipa")
otp.tip = m.Get("subject")
otp.boja = m.Get("boja")
otpadLista.Add(otp)
End If
Next
Log ("otpadLista size:" & otpadLista.Size)
otpadLista.SortType("datumInt", True)
Else
Result = j.ErrorMessage
End If
Catch
Log(LastException)
End Try
j.Release
Log(Parameters)
Log(Result)
End Sub