Json 解析List<Domain> dataList:
domain 类设置
public class XxtsAllDomain extends BaseDomain {
private List<XxtsDomain> dataList;
}
public class XxtsDomain extends BaseDomain {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
private String userId; //用户ID
private String sbsbm; //设备识别码
private int messCount; //消息条数
}
封装代码:
XxtsAllDomain xxtsAllProc = dao.executeTsProc();
List<XxtsDomain> dataList = xxtsAllProc.getDataList();
if(dataList == null || dataList.isEmpty()){
System.out.println("no data");
return;
}
XxtsAllDomain xxtsAll = new XxtsAllDomain();
xxtsAll.setDataList(dataList);
JSONObject obj = JSONObject.fromObject(xxtsAll);
解析:
JSONObject jsonObject = JSONObject.fromObject(sb.toString());
JSONArray array = jsonObject.getJSONArray("dataList");
dataList = JSONArray.toList(array, new XxtsDomain(), new JsonConfig());