如何在Retrofit 2.0中获取JSON对象而不进行转换? [英] How to get JSON object without converting in Retrofit 2.0?
本文介绍了如何在Retrofit 2.0中获取JSON对象而不进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从REST服务器下载json对象,而无需通过GSON进行转换.但不了解Retrofit 2.0 bata 1中的make方法
I need download json object from REST server without converting by GSON. But not understand how make in Retrofit 2.0 bata 1
推荐答案
只需将JsonElement
用作您的pojo.例如
Simply use JsonElement
as your pojo. For example
在您的FlowerApi接口中:
In your FlowerApi interafce:
@GET("/flower")
Call<JsonElement> getFlowers();
在您的主要班级:
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());
}
});
实际上,响应仍然由Gson转换器转换为JsonElement
,但是您可以获得与原始响应接近的内容.
Actually, the response is still converted to JsonElement
by the Gson converter, but you can get something that is close to the raw response.
这篇关于如何在Retrofit 2.0中获取JSON对象而不进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文