Browse JsonObject Android

1

How to move an object array so that I can get the data?

    {"number1":"value1", "number2":"value2", "number3":"value3"} 

  for (int c = 0; c < jsonObject.length(); c++) {

  }
    
asked by anonymous 16.02.2018 / 19:07

1 answer

2

Well, this value is actually JSONObject . An Object Array would look something like:

Object[] arr = new Object[];
List<Object> list = new ArrayList<Object>;
/* etc */

Returning to the subject, you can capture keys . This catch will return you a Iterator .

With this Iterator you can traverse all keys and thus capture the values through a while or do..while

JSONObject j = new JSONObject("{\"number1\":\"value1\", \"number2\":\"value2\", \"number3\":\"value3\"} ");
Iterator<String> keys = j.keys();

// Verifica se há mais alguma key
while (keys.hasNext() {
    // Captura a key e seu valor; e avança para a próxima
    System.out.println( j.get( keys.next() ).toString() );
}

Or you can use for

JSONObject j = new JSONObject("{\"number1\":\"value1\", \"number2\":\"value2\", \"number3\":\"value3\"} ");

for ( Iterator<String> Keys = j.keys(); Keys.hasNext(); ) {
    System.out.println( j.get( Keys.next() ).toString() );
}
    
16.02.2018 / 19:48