一、json 字符串轉 map集合,主要是通過迭代器遍歷json,然后再把 鍵值對逐個put() 進map 集合
1. 先導入maven依賴
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.32</version> </dependency>
2. json 字符串轉 map集合
// json轉map集合 public static Map<String, String> jsonToMap(String json){ // json字符串轉JSONObject對象 JSONObject jsonObject = JSONObject.parseObject(json); Iterator<Map.Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); HashMap<String, String> map = new HashMap<>(); while (iterator.hasNext()){ Map.Entry<String, Object> next = iterator.next(); map.put(next.getKey(), next.getValue().toString()); } return map; }