json字符串和List<Map<String,Object>>相互转化

 json 转为 List>

public static List> toListMap(String json){
        List list =JSON.parseArray(json);
         
        List< Map> listw = new ArrayList>();
        for (Object object : list){
            Map ageMap = new HashMap();
            Map  ret = (Map) object;//取出list里面的值转为map
            listw.add(ret);
        }
        return listw;
         
    } 
  

List> 转为 json(String)

List> list= openDao.queryForList(map);

String str = JSON.toJSONString(list); //此行转换

caChe.writeFile(finerPath,finerPath+"finerCaChe.txt",str);

 

你可能感兴趣的:(java)