I get the following error when attempting to parse a json file:
The json file structure is:
The json file is received, as can be seen in: "Log(MyStr)"
The error occurs in line: "Dim root As Map = parser.NextObject"
My Code:
Is this possibly a problem with:
Dim MyStr As String
MyStr = BytesToString(Buffer,0,Buffer.Length,"UTF-8")
B4X:
Waiting for debugger to connect...
Program started.
POST /01854fac5301ace2a54502 HTTP/1.1
content-length: 62
accept-language: fr
host: 165.73.80.252:17178
content-type: application/json
accept-encoding: gzip,deflate
user-agent: SIGFOX
accept-charset: UTF-8;q=0.9,*;q=0.7
{
"device":"BC5974",
"data":"01854fac5301ace2a54502"
}
Error occurred on line: 104 (Main)
java.lang.RuntimeException: JSON Object expected.
at anywheresoftware.b4j.objects.collections.JSONParser.NextObject(JSONParser.java:50)
at b4j.example.main._astream_newdata(main.java:332)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$2.run(BA.java:230)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
The json file structure is:
B4X:
{
"device":"{device}",
"data":"{data}"
}
The error occurs in line: "Dim root As Map = parser.NextObject"
My Code:
B4X:
Sub AStream_NewData (Buffer() As Byte)
Dim MyStr As String
MyStr = BytesToString(Buffer,0,Buffer.Length,"UTF-8")
Log(MyStr)
Dim parser As JSONParser
parser.Initialize(MyStr)
Dim root As Map = parser.NextObject
Dim data As String = root.Get("data")
Dim device As String = root.Get("device")
Log(data)
Log(device)
' Close Connection
Disconnect
End Sub
Is this possibly a problem with:
Dim MyStr As String
MyStr = BytesToString(Buffer,0,Buffer.Length,"UTF-8")