public static void handle(String str){
//str为json格式的字符串
JSONObject json = (JSONObject)JSONValue.parse(str);
Iterator iter = json.keySet().iterator();
while(iter.hasNext()) {
String key = iter.next().toString();
String val = json.get(key).toString();
System.out.println("[key=" + key + ", val=" + val + "]");
}
}
使用时需要添加一个jar包,当字符串的格式不是json格式的时候,会报NullPointerException