后台处理JSON数据

来源:互联网 发布:高洛峰php 编辑:程序博客网 时间:2024/06/08 18:35
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);}}

0 0
原创粉丝点击