您的位置:首页 > Web前端 > JavaScript

json转换实体bean、数组list

2015-07-14 15:08 555 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: