1. 程式人生 > >retrofit請求直接返回string

retrofit請求直接返回string

1.新增gradle依賴:

compile com.squareup.retrofit2:converter-scalars:2.0.0'
2.更換轉換器
mRetrofit = Retrofit.Builder()
                .baseUrl(HttpAddress.SITE)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
3.定義返回型別為string

new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, retrofit2.Response<String> response) {
                Log.d("debug", response.body());
            }

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

            }
        }