0
私はちょうどretrofitライブラリの助けを借りてユーザーの詳細を取得しようとします、それはnullを返しますが、事前に同じ入力でクライアントを休んで、それは働いています正しく。アンドロイドでヌルを返すRetrofit
マイApiClient
Public class Apiclient{
public static final String BASE_URL = Webconstants.COMMON_URL;
private static Retrofit retrofit = null;
public static Retrofit getclient() {
if (retrofit== null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
マイApiInterface
@Headers({"Content-Type: application/json"})
@POST("user/GetUserDetails")
Call<LoginResponce> Login(@Body JSONObject data);
そして
private void loginTask(JSONObject input){
ApiInterfaces apiService = Apiclient.getClient().create(ApiInterfaces.class);
Call<LoginResponce> login_call=apiService.Login(input);
login_call.enqueue(new Callback<LoginResponce>(){
@Override
public void onResponce(Call<LoginResponce> call, Responce<LoginResponce> responce) {
Error error = responce.body().getError;
if(error.getError_data() == 0){
User user = responce.body.getUser();
}else{
}
}
@Override
public void onFailure(Call<LoginResponce> call, Throwable t){
}
});
}
}
LoginResponceモデル
ようなものを呼び出しますpublic class LoginResponce {
@SerializedName("error")
private Error error;
@SerializedName("users")
private User user;
public Error getError(){ return error;}
public User getUser(){ return user;}
}
エラーとユーザーは同じ種類のモデルです。高度なレストクライアントでは、Content-Type
はapplication/json
です。