码迷,mamicode.com
首页 > 编程语言 > 详细

json转换实体bean、数组list

时间:2015-07-14 17:08:28      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

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);

 

json转换实体bean、数组list

标签:

原文地址:http://www.cnblogs.com/xiaohaizhuimeng/p/json.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!