java merge json
public void import7(){ List<Map<String, Object>> list = jdbcTemplate .queryForList("SELECT img_md5,tag_json FROM tag_img WHERE type_id='ff4dfd4ba7d949958b3d630a90fcca75' and tag_flag=1 and del_flag=1"); System.out.println(list.size()); int i=0; for(Map<String,Object> tagimg:list){ i++; System.out.println(i); String imgMd5 = tagimg.get("img_md5").toString(); JSONArray array=JSONArray.parseArray(tagimg.get("tag_json").toString());//得到原来的json TagImgFilter filter = new TagImgFilter();//更改的集合 filter.setEq_orgId("c1fa7ba875fa4c9a899e2787eb79e802"); filter.setEq_setId("47889ca50c0849dfb6cd6070ab2ddc46"); filter.setEq_typeId("114e2331338e481cb4fd3a65aff4bfc8"); filter.setEq_imgMd5(imgMd5); TagImg imgnew = tagImgService.selectAll(filter).get(0); JSONArray arraynew = new JSONArray(); if(imgnew.getTagJson() != null){ arraynew=JSONArray.parseArray(imgnew.getTagJson()); } /*if(array.size()!=8){ System.out.println("不足8个框"+array.size()+" img_md5:"+tagimg.get("img_md5").toString()); break; }*/ for(int countjson=0;countjson<array.size();countjson++){ JSONObject jsonObj = array.getJSONObject(countjson); arraynew.add(jsonObj); } System.out.println(arraynew); imgnew.setTagJson(arraynew.toString()); tagImgService.save(imgnew); } /*List<Map<String, Object>> list = jdbcTemplate .queryForList("SELECT img_md5,tag_json FROM tag_img WHERE type_id='52336e7e43204fa68c006692b355137a'"); System.out.println(list.size()); int i=0; for(Map<String,Object> tagimg:list){ i++; System.out.println(i); String imgMd5 = tagimg.get("img_md5").toString(); JSONArray array=JSONArray.parseArray(tagimg.get("tag_json").toString());//得到原来的json TagImgFilter filter = new TagImgFilter();//更改的集合 filter.setEq_orgId("c1fa7ba875fa4c9a899e2787eb79e802"); filter.setEq_setId("47889ca50c0849dfb6cd6070ab2ddc46"); filter.setEq_typeId("56329bfd7ad14d039cd1fdc4bc726316"); filter.setEq_imgMd5(imgMd5); TagImg imgnew = tagImgService.selectAll(filter).get(0); JSONArray arraynew=JSONArray.parseArray(imgnew.getTagJson()); if(array.size()!=8){ System.out.println("不足8个框"+array.size()+" img_md5:"+tagimg.get("img_md5").toString()); break; } for(int countjson=0;countjson<array.size();countjson++){ JSONObject jsonObj = array.getJSONObject(countjson); arraynew.add(jsonObj); } System.out.println(arraynew); imgnew.setTagJson(array.toString()); tagImgService.save(imgnew); } */ }