使用JsonObject生成的json,格式很差看,少了換行和縮進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);