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);

 

posted @ 2018-03-06 15:29  乱码出黑客  阅读(363)  评论(0编辑  收藏  举报