json字符串转Map集合

/**
 * json字符串转list
 * @param jsonStr
 * @return
 */
public static List<Map<String,Object>> GetJsonListByString(String jsonStr){
    List<Map<String, Object>> rsList = new ArrayList<>();
    try {
        JSONArray arry = JSONArray.parseArray(jsonStr);
        for (int i = 0; i < arry.size(); i++)
        {
            JSONObject jsonObject = arry.getJSONObject(i);
            Set<String> stringSet = jsonObject.keySet();
            Map<String, Object> map = new HashMap<>();
            for (String key :stringSet){
                Object value = jsonObject.get(key);
                map.put(key, value);
            }
            rsList.add(map);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rsList;
}

 

posted on 2023-03-03 08:35  五官一体即忢  阅读(105)  评论(0编辑  收藏  举报

导航