B4J Question Problem parsing JSON

wl

Well-Known Member
Licensed User
Hi,

I use the JSONGenerator to generate a JSON string; but have a problem parsing it using the JSONParser:

The generated JSON is:

B4X:
[
  {
  "data": {
  "id": 3906,
  "lastname": "LastName 0",
  "lcv": 0,
  "firstname": "FirstName 0"
  },
  "meta": {
  "id": 1321,
  "tableid": 3906,
  "status": "I",
  "tablename": "authors",
  "datetime": 20150111181016
  }
  },
  {
  "startid": -1,
  "batchsize": -1,
  "complete": false,
  "controller": 1,
  "password": ""
  }
]
I parse it with:

B4X:
Dim json As JSONParser
json.Initialize(jsonStatements) 'this string contains the JSON text above
mMapper.SQL.BeginTransaction
item = json.NextObject
the NextObject generates following exception:

B4X:
ava.lang.RuntimeException: JSON Object expected.
at anywheresoftware.b4j.objects.collections.JSONParser.NextObject(JSONParser.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:446)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:426)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:500)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:103)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:292)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:28)
Thanks !
 

wl

Well-Known Member
Licensed User
OK, found it .. The JSON contains in fact a list, so I should have started with json.NextArray
 

wl

Well-Known Member
Licensed User
Thanks Erel.

Indeed, I forgot this tool existed. But it would have been very helpful indeed ...
 
Top