I am making a listview
through a json that I bring from a server. The detail is that I can not pass my data to listview
in this function I try to save them from there to move them to listview
public ArrayList<String> ObtDatosJSON(String response) {
ArrayList<String> listado = new ArrayList<String>();
try {
JSONArray jsonArray = new JSONArray(response);
String texto;
for (int i=0;i<jsonArray.length();i++){
texto= jsonArray.getJSONObject(i).getString("Nombre")+ " " +
jsonArray.getJSONObject(i).getString("Direccion") + " " +
jsonArray.getJSONObject(i).getString("Telefono") + " " ;
listado.add(texto);
Log.d("Arreglo de texto",texto);
}
}catch(Exception e){
e.printStackTrace();
}
This is an example of my JSON:
{
"Datos": [
{
"Nombre": "Fitzgerald, Travis, Prescott, Declan",
"Direccion": "6088 Tincidunt, Ave",
"Telefono": "0500 772161"
},
{
"Nombre": "Emmanuel, Buckminster, Karly, Dexter",
"Direccion": "1711 Luctus Rd.",
"Telefono": "(016977) 4322"
},
{
"Nombre": "Cecilia, Wynter, Madonna, Kasimir",
"Direccion": "756-1905 Semper St.",
"Telefono": "0800 1111"
},
{
"Nombre": "Kelly, Quail, Nasim, Alea",
"Direccion": "1449 Risus, Av.",
"Telefono": "0800 518475"
},
]
}
If I remove it "Datos"
: my function if it brings them and saves them but if I do not remove it does not get it (enter the JsonException
)
Any suggestions?