Question: Help with parsing through JSON object: here is the json object, I need to get the value of lat and long and store it into

Help with parsing through JSON object:

Help with parsing through JSON object: here is the json object, I

here is the json object, I need to get the value of lat and long and store it into

String latLong = lat + "," +long;

here is my code, what am i doing wrong?:

private static String parseGeocodeResponse(String response)

{

// TODO 4: Convert response string to JSON & dive down into JSON response to get lat/long

//convert string to JSONObject

JSONObject objResponse = new JSONObject(response);

//Get results array

JSONArray arrResults = objResponse.getJSONArray("results");

for (int r = 0; r

JSONObject objResult = arrResults.getJSONObject(r);

//looks through json object to get name and vicinity/address

//get name and address

String addressLat = objResult.getString("lat");

String addressLong = objResult.getString("long");

String latLong = addressLat + "," + addressLong;

}

return latLong;

}

- results: + address_components: [ formatted address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", - geometry: 1 + bounds: ...), location: \ lat: 38.8976633, lng:77.0365739 location type: "ROOFTOP", + viewport: [... 1, place_id: "ChIJGVtI4by3t4kRr51d Qm_x58", types: [.] 1, status: "OK" - results: + address_components: [ formatted address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", - geometry: 1 + bounds: ...), location: \ lat: 38.8976633, lng:77.0365739 location type: "ROOFTOP", + viewport: [... 1, place_id: "ChIJGVtI4by3t4kRr51d Qm_x58", types: [.] 1, status: "OK

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!