How to know the order in which the columns of a query arrive

1

I'm doing an app with Android Studio and I'm using the Volley liberty to consume a service.

The web service gives me this data.

in JSON format, but I would like to know how to do with a cycle to get the name of the columns, } given that to get the data I do this.

JSONObject value = response.getJSONObject(0);
//si quiero obtener el apellido hago esto
apellito.setText = value.getString("apellido");

but how could I do to avoid this value.getString("apellido") and do it by the order of the columns and thus be able to use it with a cycle, something like that.

for(int i=0;i<tamaño;i++)
{
    valor.setText = value.getColumnIndex(i) 
    //getColummIndex lo acabo de inventar, es para que se entienda
}

and as I said "avoid this"

nombre.setText = value.getString("nombre");
apellido.setText = value.getString("apellido);
.
.
.
ingreso.setText = String.valueOf(value.getDouble("ingresoanual"))

and so depending on how many columns arrive.

I attach my JSON.

  

[{"id": "1", "name": "Alan", "last names": "Garcia", "party": "APRA", "estudiouni": "SI", "estudionouni": " SI "," estudiotec ":" NO "," anualanual ":" 1000000 "}, {" id ":" 2 "," nombre ":" Alejandro "," apellido ":" Toledo "," partido ":" Peru   Possible "," estudiouni ":" SI "," estudionouni ":" SI "," estudiotec ":" NO "," anualanual ":" 1350000 "}, {" id ":" 3 "," nombre ":" Ollanta "," last names ":" Hulama "," party ":" Party   Nationalist   Peruvian "," estudiouni ":" SI "," estudionouni ":" NO "," estudiotec ":" NO "," anualanual ":" 900000 "}, {" id ":" 4 "," nombre ":" Alberto "," last names ":" Fujimori "," party ":" Change   90 "," estudiouni ":" NO "," estudionouni ":" SI "," estudiotec ":" NO "," anualanual ":" 9999999 "}]

    
asked by Angel Cayhualla 17.08.2018 в 23:15
source

1 answer

2
Iterator<String> iter = json.keys();
while (iter.hasNext()) {
    String key = iter.next();
    try {
        String value = json.getString(key);
    } catch (JSONException e) {
        // Something went wrong!
    }
}

or put the try cath out of the while

    
answered by 17.08.2018 / 23:24
source