mbubnjaric
Member
Hi!
I am trying to parse this JSON response but having trouble with elements:
with this code:
But I am getting error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at line "For each".
Can anyone help me because I'm novice in B4X.
Thanx in advance!
I am trying to parse this JSON response but having trouble with elements:
JSON:
{"Success":true,"dtRaspored":"[{\"datum\":\"2024-03-11T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-03-11T12:00:00\",\"endTime\":\"2024-03-11T12:00:00\",\"nazivTipa\":\"Plavi spremnik\",\"boja\":\"#0000FF\",\"subject\":\"Papir - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - papir\"},{\"datum\":\"2024-08-26T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-08-26T12:00:00\",\"endTime\":\"2024-08-26T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-10-07T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-10-07T12:00:00\",\"endTime\":\"2024-10-07T12:00:00\",\"nazivTipa\":\"Crni spremnik\",\"boja\":\"#000000\",\"subject\":\"Mijesani komunalni otpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - mijesani komunalni otpad\"},{\"datum\":\"2024-01-29T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-01-29T12:00:00\",\"endTime\":\"2024-01-29T12:00:00\",\"nazivTipa\":\"Crni spremnik\",\"boja\":\"#000000\",\"subject\":\"Mijesani komunalni otpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - mijesani komunalni otpad\"},{\"datum\":\"2024-08-26T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-08-26T12:00:00\",\"endTime\":\"2024-08-26T12:00:00\",\"nazivTipa\":\"Crni spremnik\",\"boja\":\"#000000\",\"subject\":\"Mijesani komunalni otpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - mijesani komunalni otpad\"},{\"datum\":\"2024-08-12T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-08-12T12:00:00\",\"endTime\":\"2024-08-12T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-03-18T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-03-18T12:00:00\",\"endTime\":\"2024-03-18T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-09-23T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-09-23T12:00:00\",\"endTime\":\"2024-09-23T12:00:00\",\"nazivTipa\":\"Crni spremnik\",\"boja\":\"#000000\",\"subject\":\"Mijesani komunalni otpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - mijesani komunalni otpad\"},{\"datum\":\"2024-07-01T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-07-01T12:00:00\",\"endTime\":\"2024-07-01T12:00:00\",\"nazivTipa\":\"Plavi spremnik\",\"boja\":\"#0000FF\",\"subject\":\"Papir - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - papir\"},{\"datum\":\"2024-04-22T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-04-22T12:00:00\",\"endTime\":\"2024-04-22T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-08-05T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-08-05T12:00:00\",\"endTime\":\"2024-08-05T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-04-01T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-04-01T12:00:00\",\"endTime\":\"2024-04-01T12:00:00\",\"nazivTipa\":\"SmeDi spremnik\",\"boja\":\"#663300\",\"subject\":\"Biootpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - biootpad\"},{\"datum\":\"2024-04-22T00:00:00\",\"danUTjednu\":\"Monday\",\"startTime\":\"2024-04-22T12:00:00\",\"endTime\":\"2024-04-22T12:00:00\",\"nazivTipa\":\"Crni spremnik\",\"boja\":\"#000000\",\"subject\":\"Mijesani komunalni otpad - 06:00\",\"description\":\"GORNJI KNEGINEC - Skupina A - mijesani komunalni otpad\"}]","Message":"sysMsgNodata"}
with this code:
B4X:
Dim jRoot As Map = parser.NextObject
Dim Message As String = jRoot.Get("Message")
Dim dtRaspored As List = jRoot.Get("dtRaspored")
Dim Success As String = jRoot.Get("Success")
Log("*********************")
Log(dtRaspored)
For Each i As String In dtRaspored
Log(i)
Next
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at line "For each".
Can anyone help me because I'm novice in B4X.
Thanx in advance!