JSON Iteration

suggest change

Iterate over JSONObject properties

JSONObject obj = new JSONObject("{\"isMarried\":\"true\", \"name\":\"Nikita\", \"age\":\"30\"}");
Iterator<String> keys = obj.keys();//all keys: isMarried, name & age
while (keys.hasNext()) {                      //as long as there is another key
      String key = keys.next();               //get next key 
      Object value = obj.get(key);            //get next value by key
      System.out.println(key + " : " + value);//print key : value

Iterate over JSONArray values

JSONArray arr = new JSONArray();        //Initialize an empty array
//push (append) some values in:
for (int i = 0; i < arr.length(); i++) {//iterate over all values
    Object value = arr.get(i);          //get value
    System.out.println(value);          //print each value

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents