【发布时间】:2016-01-26 03:34:51
【问题描述】:
我使用HttpLoggingInterceptor 设置了我的改造,如下所示:
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.setPrettyPrinting() // Pretty print
.create();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();
在我的 Gson 实例上,我执行了 setPrettyPrinting 并且仍然得到紧凑的 JSON 输出。
这是我的图书馆。
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
如何使用 Retrofit 2 实现漂亮的打印效果? 谢谢。
编辑:更新了我的库,但仍然没有工作
【问题讨论】: