答案 0 :(得分:1)
步骤1:
从JSON创建对象。你可以使用jsonToPojo android studio插件。
步骤2:
来自onResponse的处理结果:
ApiCall apiService = ApiClient.getClient().create(ApiCall.class);
Call<Api> callForLogin = apiService.getLoginResult("user_name","Password");
callForDrawList.enqueue(new Callback<LoginResultObject>() {
@Override
public void onResponse(Call<LoginResultObject> call, Response<LoginResultObject> response) {
String accessToken=response.body().getAccessToken());
}
@Override
public void onFailure(Call<DrawResultsApi> call, Throwable t) {
}
});
我认为它可以帮助你... 感谢
答案 1 :(得分:1)
我假设您知道如何使用改造。你需要的东西只是一个简单的请求,如下所示:
call.enqueue(new Callback<AuthenticationResponse>() { @Override public void onResponse(Call<AuthenticationResponse> call, Response<AuthenticationResponse> response) { if (response.code() == 200) mAuthenticateView.showPhoneNumberSentSuccessfully(response.body().getToken(), response.body().getExpiresIn()); else mAuthenticateView.showMessage(response.message()); } @Override public void onFailure(Call<AuthenticationResponse> call, Throwable t) { } });
有关更多信息,请参阅本教程: Using Retrofit 2.x as REST client