波神

导航

以json格式打印实体类信息

1、pom.xml

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.4</version>
        </dependency>

2、使用方法

     /**
      * 格式化json
      * @param uglyJSONString
      * @return
      */
     public static String jsonFormatter(Object uglyJSON){
         if(uglyJSON == null ){
             return "";
         }
         Gson gson = new GsonBuilder().setPrettyPrinting().create();
         JsonParser jp = new JsonParser();
         String prettyJsonString = gson.toJson(uglyJSON);
         return prettyJsonString;
     }

 

posted on 2017-03-15 14:46  波神  阅读(1671)  评论(0编辑  收藏  举报