I have a JSONArray and inside that, there are many JSONObjects.
A sample of the object is:
{
"geometry": {
"type": "Point",
"coordinates": [
11.245292261254553,
43.77014284210037
]
},
"type": "Feature",
"properties": {
"nome": "Biblio",
"type": "bibl",
"email": "[email protected]",
"note": "",
"indirizzo": "ERINI",
"numero": "19"
},
"id": 1
},
All these objects are inside the features
array.
So I did this:
try {
array = json.getJSONArray("features");
for (int i = 0; i < array.length(); i++) {
Gson gson = new Gson();
}
}
But I can not figure out, how I can define geometry
and properties
attributes in the class for parsing the JSONObject.
I try with:
public class Point {
@SerializedName("geometry")
private Geometry geometry;
@SerializedName("id")
private String id;
@SerializedName("type")
private String type;
@SerializedName("properties")
private Properties properties;
public Geometry getGeometry() {
return geometry;
}
public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
public class Geometry {
@SerializedName("type")
private String type;
@SerializedName("coordinates")
private Coordinates coordinates;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Coordinates getCoordinates() {
return coordinates;
}
public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}
}
public class Coordinates {
}
public class Properties {
@SerializedName("nome")
private String nome;
@SerializedName("tipo")
private String tipo;
@SerializedName("email")
private String email;
@SerializedName("note")
private String note;
@SerializedName("indirizzo")
private String indirizzo;
@SerializedName("numero")
private String numero;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getIndirizzo() {
return indirizzo;
}
public void setIndirizzo(String indirizzo) {
this.indirizzo = indirizzo;
}
public String getNumero() {
return numero;
}
public void setNumero(String numero) {
this.numero = numero;
}
}
Create models for
"geometry"
and"properties"
Full object:
"coordinates"
is an array accordingly to your JSON