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

 

相关文章:

  • 2021-12-25
  • 2021-08-04
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案