java遍历 JSONObject 中的 key 和 value

遍历 JSONObject 中的 key 和 value

import org.json.JSONArray;
import org.json.JSONObject;

public class TestJSONArrayList {
    public static void main(String[] args) {
        String arr = "{\"map1\":[{\"ref_nbr\":\"AndroidAyh64534669859ECy3T20zHTABANK\",\"policy_no\":\"1010005242020C0003295\"}]";
        arr = arr + ",\"map2\":[{\"ref_nbr\":\"IOSAyh64534669859ECy3T20zHTABANK\",\"policy_no\":\"1010005242020C0003296\"}]}";
        System.out.println(arr);
        JSONObject array = new JSONObject(arr);
        Iterator<String> it = array.keys();
        while (it.hasNext()){
            String key1 = it.next();
            JSONArray value = array.getJSONArray(key1);
            System.out.println(value);
            System.out.println(value.getJSONObject(0));
            String ref_nbr = value.getJSONObject(0).getString("ref_nbr");
            String policy_no = value.getJSONObject(0).getString("policy_no");
            System.out.println(ref_nbr);
            System.out.println(policy_no);
        }
    }
}