json美化格式
使用JsonObject生成的json,格式不好看,少了换行和缩进
//组装成需要的json JSONObject finalJson = new JSONObject();
........ //美化 ObjectMapper mapper = new ObjectMapper(); Object obj = mapper.readValue(finalJson.toString(), Object.class); String beautify = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj); logger.debug("美化后:{}",beautify);