JSON-Objekt mit der leeren Felder

Ich bin immer in der Liste der Orte von foursquare und ich brauche den Namen, die Adresse und die Stadt, jeder Ort, die ich bekomme. Hier mein problem ist, wenn die Adresse oder die Stadt leer ist, gibt es einen Fehler und sagt "JSON Ausnahme: Kein Wert für Adresse". Ich habe versucht, verschiedene Möglichkeiten, es zu beheben, aber konnte das problem nicht lösen. Ich hoffe Ihr könnt mir helfen. Danke.

JSONObject b = venues.getJSONObject(i);
JSONObject location = b.getJSONObject("location");

String name = "";
String address = "";
String city = "";

if ("".equals(b.get("name"))) {
    // Toast.makeText(Activity2.this,"Name of Place: " +name+ " Location: "+country, Toast.LENGTH_SHORT).show();
    name = "No place ";
} else {
    name = b.getString("name");
}

if ("".equals(location.getString("address"))) {
    address = "No address";
} else {
    address = location.getString("address");
}

if ("".equals(location.getString("city"))) {
    city = "No city";
} else {
    city = location.getString("city");
}

name = "Name of the place: " + name; 
//+ " Address: "+ address + "  City: " + city;
list.add(name);
Schreibe einen Kommentar