Hi all
I am decoding JSON string sucesfully by using this code:
But now i need to sort data by a specific key value (OrTick) inside the JSON string and the code is:
Now it raises an error saying:
Where i am wrong?
I am decoding JSON string sucesfully by using this code:
B4X:
DecodificatoreMappeJSON.Initialize(DatiMappe)
ListaDatiMappe = DecodificatoreMappeJSON.NextArray
For Each coordinata As Map In ListaDatiMappe
....
Next
But now i need to sort data by a specific key value (OrTick) inside the JSON string and the code is:
B4X:
DecodificatoreMappeJSON.Initialize(DatiMappe)
ListaDatiMappe = DecodificatoreMappeJSON.NextArray
'----Code for Sorting
Dim DecodificatoreSingoloValore1 As JSONParser
Dim DecodificatoreSingoloValore2 As JSONParser
Dim swapped As Boolean
Dim ValoreTemporaneo As String
swapped = True
Do While swapped
swapped = False
For i = 1 To ListaDatiMappe.Size - 1
DecodificatoreSingoloValore1.Initialize(ListaDatiMappe.Get(i-1))
DecodificatoreSingoloValore2.Initialize(ListaDatiMappe.Get(i))
Dim root1 As Map = DecodificatoreSingoloValore1.NextObject
Dim root2 As Map = DecodificatoreSingoloValore2.NextObject
Dim OraIniziale1 As String = root1.Get("OrTick")
Dim OraIniziale2 As String = root2.Get("OrTick")
If OraIniziale1 < OraIniziale2 Then
ValoreTemporaneo = ListaDatiMappe.Get(i)
ListaDatiMappe.Set(i, ListaDatiMappe.Get(i-1))
ListaDatiMappe.Set(i-1, ValoreTemporaneo)
swapped = True
End If
Next
Loop
'-----End of Code for Sorting
For Each coordinata As Map In ListaDatiMappe
....
Next
Now it raises an error saying:
B4X:
For Each coordinata As Map In ListaDatiMappe
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at polka.app.main._jobdone(main.java:3193)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:981)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Where i am wrong?