json数据格式的转换-(list,对象)
JSON格式解析:
{"data":{"id":166,"sumProductive":468}}
//getJSONObject("data"),对data进行剥离,返回 jsonObject对象
JSONObject jsonObject = JSON.parseObject(string).getJSONObject("data");
//JSON.toJavaObject 将 jsonObject对象转换成 自建对象 cyDepcombin,用来调用自己属性的get,set方法:解析成对象
CyDepcombin cyDepcombin = JSON.toJavaObject(jsonObject, CyDepcombin.class);
将字符串转换成数组:
System.out.println("string = " + string);
String rowData = JSON.parseObject(string).getJSONObject("data").getString("rowData");//对json进行解析
JSONObject jsonResult = JSON.parseObject(rowData);//对json进行解析成对象
List<Deptzi> list = jsonResult.getList("children",Deptzi.class);//对json进行解析成对象的list数组
Deptzi deptzi = JSON.toJavaObject(jsonResult, Deptzi.class);//将对象转成自己的对象属性值
deptzi.setChildren(list);
System.out.println("list2 = "+deptzi.getChildren());
Deptzhu deptzhu = JSON.toJavaObject(jsonResult, Deptzhu.class);
System.out.println("list2 = "+deptzhu);
Integer deptzhuId = deptzhu.getDeptzhuId();
deptzhu.setId(deptzhuId);
System.out.println("deptzhuId = " + deptzhu);
//使用toArray(T[] a)方法
String[] array2 = testList.toArray(new String[testList.size()]);
//批量删除
Integer[] array2=null;
ArrayList<Integer> objects = new ArrayList<>();
List<CyDeptsalesexcel> cyDeptsalesexcels = cyDeptsalesexcelService.selectCyDeptsalesexcelList(cyDeptsalesexcel);
for (int i = 0; i < cyDeptsalesexcels.size(); i++) {
Integer id = cyDeptsalesexcels.get(i).getId();
objects.add(id);
}
//将查询出来的填报派单的模板数据的id 存放到list中
//调用批量删除
array2 = objects.toArray(new Integer[objects.size()]);//将arrays转成list
JSONObject jsonResult = JSON.parseObject(barcodeIdList);
JSONArray list = jsonResult.getJSONArray("barcodeIdList");
//List<ListMapper> listMapper = new ArrayList<>(); 导入 TypeReference包
List<ListMapper> listMapper = JSONObject.parseObject(String.valueOf(list), new TypeReference<List<ListMapper>>(){});

{
"data": {
"id": [
"6041639915183931392",
"6041643056169222144"
]
}
}
调用的参数方法,取id参数
public AjaxResult removedele(
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人