WANG 5 жил өмнө
parent
commit
d6c5703417

+ 16 - 0
src/main/java/cn/com/qmth/examcloud/commons/util/JsonUtil.java

@@ -87,6 +87,22 @@ public class JsonUtil {
 		return builder.create().toJson(obj);
 	}
 
+	/**
+	 * 格式化json
+	 *
+	 * @author WANGWEI
+	 * @param json
+	 * @return
+	 */
+	public static String format(String json) {
+		if (null == json) {
+			return json;
+		}
+		JsonParser jsonParser = new JsonParser();
+		JsonElement jsonEl = jsonParser.parse(json);
+		return toPrettyJson(jsonEl);
+	}
+
 	/**
 	 * json转对象
 	 *