Hi,
I've found this example in the forum
I've reduced the example to this to try to debug
I get an error at "jp.NextArray" assignation
Can you help me understanding where the issue is?
Thanks!
I've found this example in the forum
B4X:
Sub DownloadQuote
Dim j As HttpJob
j.Initialize("", Me) 'name is empty as it is no longer needed
j.Download("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
'The result is a json string. We parse it and log the fields.
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim quotes As List = jp.NextArray
For Each quot As Map In quotes
Log("Title: " & quot.Get("title"))
Log("Content: " & quot.Get("content"))
Next
End If
j.Release
End Sub
I've reduced the example to this to try to debug
B4X:
Dim jp As JSONParser
Dim jsonSaldo As String
jsonSaldo = "{""saldoCC"":""328.00"",""saldoSyR"":""30.00"",""saldoCB"":""0.00"",""cbPoints"":10.0,""Msg"":""OK""}"
jp.Initialize(jsonSaldo)
Log("jsonSaldo: " & jsonSaldo)
Dim quotes As List = jp.NextArray
For Each quot As Map In quotes
'Log("saldoCC: " & quot.Get("saldoCC"))
Next
I get an error at "jp.NextArray" assignation
B4X:
jsonSaldo: {"saldoCC":"328.00","saldoSyR":"30.00","saldoCB":"0.00","cbPoints":10.0,"Msg":"OK"}
Error occurred on line: 112 (Main)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:79)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at mx.cclogistics.recargame.multi.main.afterFirstLayout(main.java:105)
at mx.cclogistics.recargame.multi.main.access$000(main.java:17)
at mx.cclogistics.recargame.multi.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:703)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Can you help me understanding where the issue is?
Thanks!