i know how to parse response like {\"screenTitle\":\"National Geographic\"} token.optString("screenTitle"); up to this ok.
but see this response
{
"status": "OK",
"routes": [ {
"summary": "Southern Exp",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": -34.9257700,
"lng": 138.5997300
},
"end_location": {
"lat": -34.9106200,
"lng": 138.5991300
},
i want the lat and long value. how can i achive this.
Nothing will be able to parse the string that you've provided, because it has syntax errors.
However, this is JSON. Follow the instructions of your favourite tool that supports JSON in Java.
Are you able to provide the exception that is being raised? Then I could write something more specific.
Ok, seeing that you have a JSON string (and you're possibly using JSON from here), if you want to return an array from JSON, do something like this:
Edit To get Geo-location, you will have to iterate through the array. In this example, I've taken the value from
routs[0]/legs[0]/steps[0]/start_location
Use Following depedency
Use following Code in your main method
Now use the following classes , i have generated for response to map into java
Here's a quick code to get latitude and longitude of
start_location
in the following pathroutes[0]/legs[0]/steps[0]/start_location
:This code is just to give you an idea as to how to parse objects in JSON deep down. You may want to write a generic path like query mechanism (think XPath-like) for JSON objects, which will give you objects based on query inside a JSON
e.g. In your case: