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);
将arrayslist转换成list,进行批量删除
//使用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

将 jsonarry转换成 List<ListMapper>

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>>(){});

 

json转对象集合 .net json转对象list_json转对象集合 .net

 

格式解析
{
    "data": {
        "id": [
            "6041639915183931392",
            "6041643056169222144"
        ]
    }
}
调用的参数方法,取id参数
public AjaxResult removedele(@RequestBody String string)
    {
        System.out.println("string = " + string);
        String data = JSON.parseObject(string).getString("data");//分解string类型data
        JSONObject jsonObject = JSON.parseObject(data);
        JSONArray array = jsonObject.getJSONArray("id");//分解id数组
        int row = 0;
        for (int i = 0; i < array.size(); i++) {
            row = wmMiscRcvTransService.deleteWmMiscRcvTransById(array.get(i).toString());
        }
        return toAjax(row);
    }