【发布时间】:2016-11-17 00:24:19
【问题描述】:
改造文档说:
“Retrofit默认只能将HTTP body反序列化成OkHttp的ResponseBody...可以添加转换器支持其他类型”
这意味着我应该能够使用 GSON 转换器进行 api 调用,并以“ResponseBody”对象的形式获得我的响应。
但我仍然收到错误
java.lang.IllegalArgumentException: Unable to create converter for class com.squareup.okhttp.ResponseBody
这是我的代码
@GET("v1/search")
Call<ResponseBody> getArtists(@Query("q") String name, @Query("type") String searchType);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.spotify.com/")
.build();
api = retrofit.create(SpotifyApi.class);
api.getArtists(searchBox.getText().toString(), "artist")
.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
基本上,我希望能够以最纯粹/最简单的形式使用 Retrofit,并获得基本/原始响应。这不是用于真正的应用程序,而是用于实验。
【问题讨论】: