1. 程式人生 > >JSONObject 轉換為Map

JSONObject 轉換為Map

JSONObject obj = new JSONObject();
{
obj.put("key1", "value1");
obj.put("key2", "value2");
obj.put("key3", "value3");
}
Map<String, String> params = JSONObject.parseObject(obj.toJSONString(), new TypeReference<Map<String, String>>(){});
System.out.println(params);

輸出:{key3=value3, key2=value2, key1=value1}