Question

Je suis en train d'écrire une HttpGet demande pour Android qui interroge l'api foursquare pour l'événement à proximité. Le responce JSON je reçois de retour est

{"groups": [
{
  "type": "Nearby",
  "venues": [
    {
      "id": 2587838,
      "name": "Marriott Druids Glen Hotel Newtownmountkennedy",
      "primarycategory": {
        "id": 79281,
        "fullpathname": "Travel:Resort",
        "nodename": "Resort",
        "iconurl": "http://foursquare.com/img/categories/travel/resort.png"
      },
      "address": "Newtownmountkennedy",
      "city": "Newtownmountkennedy",
      "state": "",
      "verified": false,
      "geolat": 53.091717,
      "geolong": -6.079162,
      "stats": {
        "herenow": "0"
      },
      "distance": 5596
    },

Il peut y avoir beaucoup de ces lieux. Je peux l'obtenir pour imprimer les informations de lieux en utilisant ce code

InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
Log.i("Hoosheer0",result);

// A Simple JSONObject Creation
JSONObject json=new JSONObject(result);
JSONArray venues = json.getJSONArray("groups");
//JSONArray docsArray = jObject.getJSONArray("docs");
for (int i = 0; i<venues.length();i++){
    String name = venues.getJSONObject(i).optString("venues");
    //String venueName = name.
    Log.i("This is a name... pleasse", name);
}

instream.close();

Comment puis-je accéder aux valeurs geolat & geolong?

Était-ce utile?

La solution

Je crois placer ce code dans votre boucle for devrait faire l'affaire:

JSONObject venueObject = venues.getJSONObject(i);
double geoLat = venueObject.getDouble("geolat");
double geoLong = venueObject.getDouble("geolong");

Autres conseils

Vous pouvez consulter et choisir une bibliothèque JSON à utiliser pour obtenir à ceux valeurs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top