JsonArray转换List

将List转换为JsonArray:

AppResponse<List<ProjectVo>> allProject = projectServiceFeign.findAllProject();
//转json
String toJSONString = JSON.toJSONString(allProject.getData());
//保存到redis中,设置失效时间
redisTemplate.opsForValue().set("projectStr", toJSONString,10, TimeUnit.DAYS);

JsonArray需要的格式:

[{"headerImage":"http://xue.ujiuye.com/uploads_it/2005/QuanGuo/F5Q1275748985AOH.jpg","id":6,"memberid":3,"name":"第1个项目","remark":"非常棒的项目"},{"headerImage":"http://xue.ujiuye.com/uploads_it/1912/QuanGuo/ECA932369863ODK9.jpg","id":7,"memberid":6,"name":"测试项目","remark":"这是一个好项目"}]

将JsonArray转换为List:

//从redis读取项目集合
String data = redisTemplate.opsForValue().get("projectStr");
//转换为List集合
List<ProjectVo> projectVoList = JSON.parseArray(data,ProjectVo.class);

转换完成的效果:

JsonArray转换List_第1张图片

你可能感兴趣的:(java后端,java)