刚开始写法------错误
JSONArray jsonArray = (JSONArray) this.getJsonFilter().get("ids"); PltPayDuesModel[] payDuesModels = (PltPayDuesModel[]) jsonArray.toArray();
报这个[Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
由于无法直接,因此需要曲线救国
先进行遍历,将object转化为jsonobject,在通过JSONObject的工具类转化为你想要转化的对象,代码如下
//拿到你需要转化的jsonArray数据
JSONArray jsonArray = (JSONArray) this.getJsonFilter().get("ids"); List<PltPayDuesModel> list = new ArrayList<>();
//遍历 for (Object obj : jsonArray) {
//转为JSONObject JSONObject jsonObject = JSONObject.fromObject(obj); PltPayDuesModel model = (PltPayDuesModel) JSONObject.toBean(jsonObject, PltPayDuesModel.class); list.add(model); } this.pltPayDuesService.auditPlt(list);
这样就可以了
标签:jsonArray,JSONObject,list,转化,JSONArray,报错,数组,PltPayDuesModel From: https://www.cnblogs.com/gsyy/p/17485822.html