首页 > 其他分享 >json字符串转Map集合

json字符串转Map集合

时间:2023-03-03 09:03:48浏览次数:43  
标签:jsonStr Map map json key 字符串 arry

/**
 * 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;
}

 

标签:jsonStr,Map,map,json,key,字符串,arry
From: https://www.cnblogs.com/ht-privete-logs/p/17174315.html

相关文章