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(