字符串转换为json对象:
String strResult = RestUtil.getRestContent(url+"/service/peccancy/myOrderList", mappeccancy);
JSONObject obj = JSONObject.fromObject(strResult);
json对象转换成list集合:
JSONArray objData = (JSONArray)obj.get("data"); //获取data字段
peccancyList=(List<PeccancyVO>)objData.toCollection(objData, PeccancyVO.class);
json对象转换成对象:
PeccancyVO vo=(PeccancyVO)JSONObject.toBean(obj,PeccancyVO.class);
这里注意:对象一定要有无参的构造方法,否则会报错:java.lang.nosuchmethodexception <init>
时间: 2024-11-20 07:52:11