您的当前位置:首页正文

jsonarray ---json数组格式(1对多map)

2024-11-08 来源:个人技术集锦
JSONArray jsonin = imagePath(map1);
p.setImages(jsonin.toString());


public JSONArray imagePath(Map<String, Object> map1) {
List<InterfaceUploadPicture> interfacePic= inssureService.interfacePic(map1);
JSONArray jsonin = new JSONArray();
  Set<String> set = new HashSet<String>();
  Map<String,List<String>> maporg =  new HashMap<String, List<String>>();
if(interfacePic!=null&&interfacePic.size()>0){
for(InterfaceUploadPicture pic : interfacePic){
    set.add(pic.getApplyAttributeId()+"");
}
}
Iterator<String> it = set.iterator();
   while (it.hasNext()) {
   List<String> ogmap= new ArrayList<String>();
   String attr=(String)it.next();
    for(InterfaceUploadPicture og:interfacePic){
    if(attr.equals(og.getApplyAttributeId()+"")){
    ogmap.add(WebConfig.get("ioImageurl")+og.getPictureCode());
}
    }
    maporg.put(attr, ogmap);//属性和对应的图片地址
   }
   List<InterfaceApplyAttribute> attrMapList=null;
//    List<String,Map<String,Object>> listatt= new ArrayList<String,Object>();
   Map<String,String> attrMap = new HashMap<String, String>();
  
   try {
   attrMapList= inssureService.getApplyAttributeMap();
   for(InterfaceApplyAttribute at :attrMapList){
   attrMap.put(at.getId()+"", at.getAttributeName());
   }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   Iterator<String> it1 = set.iterator();
   while (it1.hasNext()) {
  
   String attr=(String)it1.next();
   List<String> pic= maporg.get(attr);
   JSONObject jsonObject = new JSONObject();
        jsonObject.put(attrMap.get(attr),  pic);
        jsonin.add(jsonObject);
   }
return jsonin;
}
显示全文