B4J Question [SOLVED] How to extract JSONP?

javiers

Active Member
Licensed User
Longtime User
How can I extract the elements of this response:

B4X:
callback({"id":"48080","province":"Bizkaia","muni":"Valle de Trápaga-Trapagaran","type":"Municipio","address":"Valle de Trápaga-Trapagaran","postalCode":null,"poblacion":null,"geom":"POLYGON ((-3.0628470500000002 43.264890630000004, -3.0628470500000002 43.31237445, -3.00443827 43.31237445, -3.00443827 43.264890630000004, -3.0628470500000002 43.264890630000004))","tip_via":null,"lat":43.28863254,"lng":-3.0336426600000004,"portalNumber":0,"stateMsg":"Dirección no encontrada, se devuelve el municipio","state":10,"countryCode":"011","refCatastral":null})

I have used

B4X:
Dim parser As JSONParser
parser.Initialize (Job.GetString)

but I get an error

B4X:
java.lang.RuntimeException: JSON Object expected.

I would appreciate help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim s As String = $"callback({"id":"48080","province":"Bizkaia","muni":"Valle de Trápaga-Trapagaran","type":"Municipio","address":"Valle de Trápaga-Trapagaran","postalCode":Null,"poblacion":Null,"geom":"POLYGON ((-3.0628470500000002 43.264890630000004, -3.0628470500000002 43.31237445, -3.00443827 43.31237445, -3.00443827 43.264890630000004, -3.0628470500000002 43.264890630000004))","tip_via":Null,"lat":43.28863254,"lng":-3.0336426600000004,"portalNumber":0,"stateMsg":"Dirección no encontrada, se devuelve el municipio","state":10,"countryCode":"011","refCatastral":Null})"$
s = s.SubString2(s.IndexOf("{"), s.LastIndexOf("}") + 1)
Dim p As JSONParser
p.Initialize(s)
Dim m As Map = p.NextObject
Log(m)
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
@Erel

You're fast !!
 
Upvote 0

javiers

Active Member
Licensed User
Longtime User
B4X:
Dim s As String = $"callback({"id":"48080","province":"Bizkaia","muni":"Valle de Trápaga-Trapagaran","type":"Municipio","address":"Valle de Trápaga-Trapagaran","postalCode":Null,"poblacion":Null,"geom":"POLYGON ((-3.0628470500000002 43.264890630000004, -3.0628470500000002 43.31237445, -3.00443827 43.31237445, -3.00443827 43.264890630000004, -3.0628470500000002 43.264890630000004))","tip_via":Null,"lat":43.28863254,"lng":-3.0336426600000004,"portalNumber":0,"stateMsg":"Dirección no encontrada, se devuelve el municipio","state":10,"countryCode":"011","refCatastral":Null})"$
s = s.SubString2(s.IndexOf("{"), s.LastIndexOf("}") + 1)
Dim p As JSONParser
p.Initialize(s)
Dim m As Map = p.NextObject
Log(m)


Thank you!!
This community is fantastic and EREL more!!
 
Upvote 0
Top