본문 바로가기
프로그래밍/DB/JAVA/안드로이드/GAE

[안드로이드] JSON OBJECT 타입 반복문으로 가져오기.

by 아유카와 2016. 3. 26.

    JSON array 타입을 반복문으로 가져오는 것은 어려움이 없다. 하지만 JSON object로만 구성된 항목들을 반복문으로 가져오려면 어떻게 해야 할까?? 아래 예제를 참고 하면 쉽게 문제가 해결이 된다.


1. 예제예제


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

Use the keys() iterator to iterate over all the properties, and call get() for each.

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