List<Entity> entityList=new ArrayList<Entity>();
String jsondata =request.getParameter("jsondata"); //数据必须为'[..]'格式
if(jsondata!=""&&jsondata!=null){
JSONArray jsonArray = new JSONArray(jsondata); //转化为Json数组
for(int i=0;i<jsonArray.length(); i++){
org.json.JSONObject obj =jsonArray.getJSONObject(i);//将数组中的数据转为对象类型
Entity entity=new Entity();//给对象赋值
entity.setId(obj.get("id").toString()); //根据字段名获取值
entity.setName(obj.get("name").toString());
entityList.add(entity);
}
}
后台处理JSON数据
最新推荐文章于 2021-06-21 22:23:05 发布