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

前端之家收集整理的这篇文章主要介绍了jsonarray ---json数组格式(1对多map)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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; } 原文链接:https://www.f2er.com/json/289551.html

猜你在找的Json相关文章