Wer kann mir unter die Arme greifen, bekomme immer eine Fehlermeldung.
Der String dem ich vom Server erhalte:
{"message":"accurate","cod":"200","count":1,"list":[{"id":2906121,"name":"Herford","coord":{"lon":8.68333,"lat":52.133331},"main":{"temp":22.71,"pressure":1016,"humidity":40,"temp_min":20.56,"temp_max":25.1},"dt":1462535781,"wind":{"speed":6.2,"deg":130},"sys":{"country":"DE"},"clouds":{"all":40},"weather":[{"id":802,"main":"Clouds","description":"überwiegend bewölkt","icon":"03d"}]}]}
Die Fehlermeldung die kommt:
main_jobdone (java line: 368)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at anywheresoftware.b4a.wetter.main._jobdone(main.java:368)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
java.lang.RuntimeException: JSON Array expected.
Mein Code:
Der String dem ich vom Server erhalte:
{"message":"accurate","cod":"200","count":1,"list":[{"id":2906121,"name":"Herford","coord":{"lon":8.68333,"lat":52.133331},"main":{"temp":22.71,"pressure":1016,"humidity":40,"temp_min":20.56,"temp_max":25.1},"dt":1462535781,"wind":{"speed":6.2,"deg":130},"sys":{"country":"DE"},"clouds":{"all":40},"weather":[{"id":802,"main":"Clouds","description":"überwiegend bewölkt","icon":"03d"}]}]}
Die Fehlermeldung die kommt:
main_jobdone (java line: 368)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at anywheresoftware.b4a.wetter.main._jobdone(main.java:368)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
java.lang.RuntimeException: JSON Array expected.
Mein Code:
B4X:
Sub Process_Globals
Dim HttpJob1 As HttpJob
End Sub
Sub Globals
Private LabelID As Label
Private LabelName As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("wetter")
HttpJob1.Initialize("Wetter", Me)
HttpJob1.download("http://api.openweathermap.org/data/2.5/find?q=Herford&type=accurate&units=metric&lang=de&APPID=XXXXXXXXXXXXXX")
End Sub
Sub Activity_Resume
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = True Then
Dim res As String
res = Job.GetString
Log("Wetterdaten vom Server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Dim Wetter As List
Wetter = parser.NextArray 'returns a list with maps
For i = 0 To Wetter.Size - 1
Dim m As Map
m = Wetter.Get(i)
LabelID = m.Get("id")
LabelName = m.Get("name")
'usw usw usw
Next
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub