0

I do not manage to get the latitude, longitude from the following json (hold in json variable) I get from a http request:


{
  "name": "rue de la paix, paris, france",
  "Status": {
    "code": 200,
    "request": "geocode"
  },
  "Placemark": [ {
    "id": "p1",
    "address": "Rue de la Paix, 75002 Paris, France",
    "AddressDetails": {
   "Accuracy" : 6,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Ile-de-France",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Paris",
               "PostalCode" : {
                  "PostalCodeNumber" : "75002"
               },
               "Thoroughfare" : {
                  "ThoroughfareName" : "Rue de la Paix"
               }
            },
            "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 48.8724046,
        "south": 48.8661093,
        "east": 2.3343785,
        "west": 2.3280833
      }
    },
    "Point": {
      "coordinates": [ 2.3312296, 48.8692714, 0 ]
    }
  } ]
}

I first get the "Placemark" JSONArray with the following code:

JSONArray array = json.optJSONArray("Placemark");

That is ok. But I cannot get the "Point" object...

JSONObject coordinates_json_obj = json.optJSONArray("Placemark").getJSONObject(4);

 => JSONArray[4] not found.

Would you have any clue ? Thanks a lot, Luc

1 Answer 1

4

There is only one object in the Placemark array. Point is an entry in that object.

Do this, maybe:

JSONObject coordinates_json_obj = json.optJSONArray("Placemark").get(0).getJSONObject("Point");
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I am trying to get the city and country but unable to iterate through the response. Any pointers?
I have tried this but without any luck: JSONArray Placemark = obj.getJSONArray("Placemark"); JSONObject j=Placemark.getJSONObject(0); String details=j.getString("Country"); But this doesnt work :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.