无法获得改造 v2 调用响应

Unable to get retrofit v2 call response

我正在将改造 1.9 升级到 v2.1.0。我想得到响应 json 并手动转换它,但我得到的是这样的:

log res retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall@41acd528-okhttp3.ResponseBody@41ad8a18

我的代码是:

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BASIC);

    client = new OkHttpClient.Builder()
            .connectTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .addInterceptor(logging)
            .build();

        Retrofit retrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl(Config.baseEndpoint)
            .build();

    ApiService api = retrofit.create(ApiService.class);

    Call<ResponseBody> login = api.login("email", "password");

    login.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.e(TAG, "log res "+call.toString()+"-"+response.body().toString());
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {

        }
    });

使用JsonObject代替ResponseBody

Call<JsonObject> login = api.login("email", "password");

login.enqueue(new Callback<JsonObject>() {
    @Override
    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
        Log.e(TAG, "log res "+call.toString()+"-"+response.body().toString());
    }

    @Override
    public void onFailure(Call<JsonObject> call, Throwable t) {

    }
});

注意:确保使用com.google.gson.JsonObject,而不是org.json.JSONObject