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);
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);
相关文章推荐
- JavaScript中的Prototypes
- JS 实现Json查询的方法实例
- 立即执行函数写法理解
- 动态加载script文件
- 一个proxy.jsp用于openlayers的代理
- JSON与DataTable(DataSet)相互转化
- js 字符串转换成数字的三种方法
- GetListToJson
- javascript中setTimeout与setInterval用法
- javascript多线程
- JSPatch实现原理详解:让JS调用/替换任意OC方法
- JS取出字符串的12种方法
- javascript 中的location.pathname
- Json数据解析
- BZOJ 1013 [JSOI2008]球形空间产生器sphere
- JSON 基础知识
- js原型链与继承
- js 异步请求
- Extjs xx is undefined错误信息说明
- JavaScript取得WEB安全颜色列表的方法