tags:

views:

47

answers:

1

Hello, 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

+3  A: 

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");
ntownsend
Thanks, that works fine !!!
Luc