在java中格式化顯示json的幾種方式


第一種:

import com.google.gson.*;

def pretty = new GsonBuilder().setPrettyPrinting().create().toJson(new JsonParser().parse("$Parameters"))
log.info "\n 查詢H5短鏈接列表結果是: \n $pretty"


第二種:

需要導入json-io-4.12.0.jar 包

下載地址:https://jar-download.com/artifacts/com.cedarsoftware/json-io/4.13.0/source-code

import com.cedarsoftware.util.io.JsonWriter
def  pretty = JsonWriter.formatJson("$Parameters")
log.info "\n 查詢H5短鏈接列表結果是: \n $pretty"

第三種:

需要導入json-20210307.jar 包

下載地址:https://jar-download.com/maven-repository-class-search.php?search_box=org.json.JSONWriter

import org.json.*;
JSONObject jsonObject = new JSONObject("$Parameters");
def  pretty = jsonObject.toString(4);
log.info "\n 查詢H5短鏈接列表結果是: \n $pretty"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM