从一个JSON数组得到一个java对象集合

 

import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.JSONUtils;
public static List<?> getObjectList(String jsonString,Class<?> clazz){
      
     //jsonString=[{"name":"","age":"","telephone":""},{},{}] 
        JSONArray array = JSONArray.fromObject(jsonString);
        List list = new ArrayList();
        for (Iterator iterator = array.iterator(); iterator.hasNext();) {
            JSONObject jsonObject = (JSONObject) iterator.next();
            list.add(JSONObject.toBean(jsonObject, clazz));
        }
        return list;
 }

 

posted @ 2018-12-25 11:09  ffzzblog  阅读(412)  评论(0编辑  收藏  举报