标签:
实体类Javabean必须要有无参构造,否则报错
String s = req.getParameter("pakage");
s = URLDecoder.decode(s,"utf-8");
System.out.println(s);
JSONArray jsonArray = JSONArray.fromObject(s);
List list = (List) jsonArray.toCollection(jsonArray,User.class);
Iterator it = list.iterator();
while(it.hasNext())
{
User user = (User) it.next();
System.out.println(user.getName());
}
--------------------------------------------------------
//这种好用
String s = req.getParameter("pakage");
s = URLDecoder.decode(s,"utf-8");
System.out.println(s);
JSONArray jsonArray = JSONArray.fromObject(s); //将字符串 专程JSON数组
ArrayList<User> list = new ArrayList<User>();
for (int i = 0; i < jsonArray.size(); i++) {
数组遍历
JSONObject jsonObject = (JSONObject) jsonArray.get(i); 这两行就是单个对象转换
list.add((User)JSONObject.toBean(jsonObject, User.class));
}
标签:
原文地址:http://www.cnblogs.com/noteofmine/p/5469147.html