json數據格式 { "list": [ { "ann_type_name": "郵件", "anne_name": "plugin.png", "anne_path": "/jscdc/upload/eamil/plugin.png", "userid": "11e4-e6a3-4bcea910-a76f-9f966c0d602a" }, { "ann_type_name": "郵件", "anne_name": "act_6.gif", "anne_path": "/jscdc/upload/eamil/act_6.gif", "userid": "11e4-e6a3-4bcea910-a76f-9f966c0d602a" } ]} 解析代碼: String string="{\"list\":[{\"ann_type_name\":\"郵件\",\"anne_name\":\"plugin.png\",\"anne_path\":\"/jscdc/upload/eamil/plugin.png\",\"userid\":\"11e4-e6a3-4bcea910-a76f-9f966c0d602a\"},{\"ann_type_name\":\"郵件\",\"anne_name\":\"act_6.gif\",\"anne_path\":\"/jscdc/upload/eamil/act_6.gif\",\"userid\":\"11e4-e6a3-4bcea910-a76f-9f966c0d602a\"}]}"; JSONObject jsonObject = JSONObject.fromObject(string); //把json格式的字符串,轉換成json對象 //String reString = (String) jsonObject.get("arg1"); JSONArray jsonArray = jsonObject.getJSONArray("list"); //取出json對象裏面「root」數組,並轉換成JSONArray對象 Iterator<JSONArray> itr = jsonArray.iterator(); //迭代jsonArray while(itr.hasNext()) { JSONObject temp = JSONObject.fromObject(itr.next()); PublicAnne publicAnne = new PublicAnne(); publicAnne.setAnneName(temp.getString("anne_name")); publicAnne.setAnnePath(temp.getString("anne_path")); publicAnne.setAnnTypeId(mailId); publicAnne.setAnnTypeName(temp.getString("ann_type_name")); publicAnne.setUserId(receiverAllUserIds); this.cdcDao.createModel(publicAnne); }