将一个json拼接到另一个json中,生成新的json

 /**
     * 将json拼接到json中,生成新的json
     * @param jsonStrO
     * @param jsonStrO2
     * @return
     */
    public static String getJsonNew (String jsonStrO , String jsonStrO2){
        if(org.apache.commons.lang.StringUtils.isBlank(jsonStrO)){
            jsonStrO = "{}";
        }

        if(org.apache.commons.lang.StringUtils.isBlank(jsonStrO2)){
            jsonStrO = "{}";
        }

        String jsonStrN = "";
        JSONObject json = JSONObject.parseObject(jsonStrO);
        Map<String, Object> mapO = (Map<String, Object>)json;

        JSONObject json2 = JSONObject.parseObject(jsonStrO2);
        Map<String, Object> mapO2 = (Map<String, Object>)json2;

        mapO.putAll(mapO2);

        JSONObject jsonN = new JSONObject(mapO);
        jsonStrN = jsonN.toString();

        return jsonStrN;
    }

 


版权声明:本文为liuming690452074原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。