标签:
json转实体bean
data=[{"xuHao":"201407140001","scaleNo":"01","qrCode":"440100100002B993","beforeWeight":15.85,"fillingWeight":30.50,"steelno":"013267","fillingWorkerID":"","fillingDate":"2014-07-14 09:29:01"},{"xuHao":"201507140002","scaleNo":"01","qrCode":"4401001000013475","beforeWeight":15.85,"fillingWeight":30.50,"steelno":"003212","fillingWorkerID":"","fillingDate":"2015-07-14 09:33:01"}]
String strObject=request.getParameter("data");
FillingDetailRecordsEntity requestBean=(FillingDetailRecordsEntity)jsonToObject(strObject,FillingDetailRecordsEntity.class);
public static <T> T jsonToObject(String jsonString, Class<T> pojoCalss) {
try{
Object pojo;
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(jsonString);
pojo = net.sf.json.JSONObject.toBean(jsonObject, pojoCalss);
return (T)pojo;
}catch(Exception ex){
ex.printStackTrace();
return null;
}
}
json转实体数组list
JSONArray jsonArray = JSONArray.fromObject(strObject);
List<FillingDetailRecordsEntity> list = JSONArray.toList(jsonArray, FillingDetailRecordsEntity.class);
标签:
原文地址:http://www.cnblogs.com/xiaohaizhuimeng/p/json.html