是否可以在没有模型类的情况下使用改造?
问题描述:
我在改造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) {
}
});