在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