首页 前端知识 Json把String转对象、转list。把对象转json

Json把String转对象、转list。把对象转json

2024-04-29 11:04:06 前端知识 前端哥 922 554 我要收藏

Json把String转对象、转list。把对象转json

1,Json把String转对象

public Object test(String jsonStr){
JSONArray jsonArray = JSON.parseArray(jsonStr);
StudentVo studentVo = (StudentVo) JSONObject.parseArray(jsonArray.toJSONString(), StudentVo.class);
   return models;
 }
复制

2,Json把String转List

public Object test(@RequestBody Map<String, Object> map){
   String json1 = JSON.toJSONString(models.get("regionInfos"));
// 转json,这里接收的每个同类型对象都有多个,所以是个集合,需要转json
List<RegionInfo> znjsRegionInfos = JSON.parseArray(json1, RegionInfo.class);
   return models;
 }
复制

3,对象转JSON

String jsonObjectStr = JSONObject.toJSONString(studentList);
String jsonObjectStr = JSON.toJSONString(studentList);
复制
转载请注明出处或者链接地址:https://www.qianduange.cn//article/6044.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!