我需要从REST服务器下载json对象而不用GSON转换.但不明白如何制作Retrofit 2.0 bata 1
简单地JsonElement用作你的pojo.例如
在你的FlowerApi interfce中:
@GET("/flower")
Call<JsonElement> getFlowers();
Run Code Online (Sandbox Code Playgroud)
在你的主要课程中:
Call<JsonElement> getFlowersCall = httpApiClass.getFlowers();
getFlowersCall.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Response<JsonElement> response, Retrofit retrofit) {
JsonElement jsonElement = response.body();
Log.d(TAG, jsonElement.toString());
}
@Override
public void onFailure(Throwable t) {
Log.d(TAG, "Failed: " + t.getMessage());
}
});
Run Code Online (Sandbox Code Playgroud)
实际上,响应仍然JsonElement由Gson转换器转换,但是你可以获得接近原始响应的东西.
| 归档时间: |
|
| 查看次数: |
5334 次 |
| 最近记录: |