JSONObject解析List的json数据

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);
				     
				}


你可能感兴趣的:(JSONObject解析List的json数据)