是否可以在没有模型类的情况下使用改造? [英] Is it possible to use retrofit without model class?
本文介绍了是否可以在没有模型类的情况下使用改造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在改造lib中使用模型类时遇到问题.后端方字段名称已更改.
i have problem to use model class in retrofit lib. A backend side field name has changed.
是否可以在没有模型类的情况下获得响应?
Is it possible to get response without model class?
推荐答案
是的,可以.
@POST("url")
Call<JsonObject> register(@Query("name") String name,
@Query("password") String password);
只需根据您的响应而不是Model类编写JsonArray或JsonObject.
Just write JsonArray or JsonObject according to your response instead of Model class.
然后,从JsonObject或JsonArray获取数据,您将获得以下响应
Then, get data from JsonObject or JsonArray which you get in response as below
Call<JsonObject> call = application.getServiceLink().register();
call.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
JsonObject object = response.body();
//parse object
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
}
});
这篇关于是否可以在没有模型类的情况下使用改造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文