JSON problem

kkaminski

Member
Licensed User
Longtime User
Hi friends!

I have a little problem, with JSON data generated by PHP's json_encode function.

---- data generated by PHP script on server ---

{"data":[{"id":"10045","nazwa":" Centrum Sprzedaży FIAT AUTO POLAND ","adres":"Katowicka 24 ","kod":" 43-30","miejscowosc":"Bielsko-Biała","szer":"49.8515014648438","dlug":"19.035400390625"},{"id":"55835","nazwa":" Inter-Oner","adres":"Bolesława Prusa 10","kod":"43-300","miejscowosc":"Bielsko-Biała","szer":"49.8007964","dlug":"19.0572596"}],"status":"OK"}

---- end of data ----

All looks good. Top level data is represented by object, elements "data" and "status". But code presented below does'nt recognize it:
-----
Sub hcSerwis_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Dim Result, s As String
Dim i As Int
Result = Response.GetString("UTF8")
Dim json As JSONParser
json.Initialize(Result)

Dim JSONmap As Map
JSONmap = json.NextObject ' <--- error
.....
-------------
error: java.lang.ErrorException: JSON Object excepted.
JSONTokener is set at character 1 after execution json.NextObject.

BTW, similar data generated by Google Map API are parsed very well.

Any suggestion?

Have a nice day, Krzysztof
 

kkaminski

Member
Licensed User
Longtime User
OK, next test:

--------------------------
Sub hcSerwis_ResponseSuccess(Response As HttpResponse, TaskId As Int)
Dim Result, s As String
Dim i As Int
Result = Response.GetString("UTF8")
Dim json As JSONParser
json.Initialize(Result)

Dim JSONlist As List
JSONlist = json.NextArray ' <--- error
.....
-------------
error: java.lang.ErrorException: JSON Array excepted.
JSONTokener is set at character 1 after execution json.NextArray.


But I'm sure, that top level is object.

Krzysztof
 
Upvote 0

theinvensi

New Member
I'm having the same problem of kkaminski. My PHP code that generates a JSON exactly like the kkaminski and B4a of the same error. Anyone found a solution?
 
Upvote 0
Top