Я получаю ответ JSON от API Google, который я пытаюсь проанализировать. Но я получаю org.json.JSONException.Невозможно разобрать google places Ответ JSON - org.json.JSONException
Это мой ответ JSON.
Я использую следующий код для извлечения форматированного адреса.
try {
Log.e("test-ttt", jsonResults.toString());
// Create a JSON object hierarchy from the results
JSONObject jsonObj = new JSONObject(jsonResults.toString());
JSONObject placeDetailsJsonArray = jsonObj.getJSONObject("result");
// Extract the Place descriptions from the results
placeDetails = "NAME: " + placeDetailsJsonArray.getJSONObject("name").toString();
placeDetails += "ADDRESS: " + placeDetailsJsonArray.getJSONObject("formatted_address").toString();
} catch (JSONException e) {
Log.e(TAG, "Cannot process JSON results", e);
}
это исключение LogCat я получаю:
org.json.JSONException: Value South Point School at name of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:100)
at org.json.JSONObject.getJSONObject(JSONObject.java:578)
at manasthemarvel.triptimeline.PlaceAPI.getPlaceDetails(PlaceAPI.java:78)
at manasthemarvel.triptimeline.placeInfo.doInBackground(placeInfo.java:14)
at manasthemarvel.triptimeline.placeInfo.doInBackground(placeInfo.java:10)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
// Extract the Place descriptions from the results
placeDetails = "NAME: " + placeDetailsJsonArray.getJSONObject("name").toString();
placeDetails += "ADDRESS: " + placeDetailsJsonArray.getJSONObject("formatted_address").toString();
Что я здесь делаю неправильно?