获取json里所有的key-value

public static void main(String[] args) throws JSONException {
String str = "{field1:123,field2:2,field3:3}";
JSONObject jsonObject = new JSONObject(str);
Iterator<String> it = jsonObject.keys(); 
while(it.hasNext()){
// 获得key
String key = it.next(); 
String value = jsonObject.getString(key);    
System.out.println("键: "+key+",值:"+value);
}

猜你喜欢

转载自blog.csdn.net/qiyinyu2157/article/details/80492719