Optimised JsonUtil
This commit is contained in:
parent
3ba32a65f2
commit
ee230dcd62
|
@ -1,6 +1,9 @@
|
|||
package com.power.doc.utils;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
/**
|
||||
* @author yu 2021/6/26.
|
||||
|
@ -9,18 +12,20 @@ public class JsonUtil {
|
|||
|
||||
/**
|
||||
* Convert a JSON string to pretty print
|
||||
*
|
||||
* @param jsonString json string
|
||||
* @return Format json string
|
||||
*/
|
||||
public static String toPrettyFormat(String jsonString) {
|
||||
JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
JsonElement jsonElement = JsonParser.parseString(jsonString);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String prettyJson = gson.toJson(json);
|
||||
String prettyJson = gson.toJson(jsonElement);
|
||||
return prettyJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JSON to String and pretty print
|
||||
*
|
||||
* @param src Json
|
||||
* @return Format json string
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue