Java 遍历json

 

 

import java.util.Map;


import com.alibaba.fastjson.JSONObject;


public class forJson {


public static void main(String[] args) {


// TODO Auto-generated method stub


JSONObject jsonObject = new JSONObject();


jsonObject.put("key", "value");
jsonObject.put("key1", "value1");
jsonObject.put("key2", "value2");


//
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }



for (String key : jsonObject.keySet()) {

//System.out.println(key.getKey() + ":" + key.getValue());
System.out.println(key +":"+  jsonObject.getString(key));




}


}


}

上一篇:2021-07-01


下一篇:个人技术总结