我在 Android Studio 中使用 Retrofit,我有两个调用来执行不同的模型和 url 路径(基本 url 相同)。
这里是我的 api 接口:
public interface ApiService {
String BASE_URL = "https://pro-api.coinmarketcap.com/";
@GET("v1/cryptocurrency/info")
@Headers("X-CMC_PRO_API_KEY: e55f2098-41ad-4a72-871e-d0dfae6d4502")
Call<Crypto> cryptoCurrencyInfo(
@Query("id") String id
);
@GET("v1/cryptocurrency/listings/latest")
@Headers("X-CMC_PRO_API_KEY: e55f2098-41ad-4a72-871e-d0dfae6d4502")
Call<CryptoCurrency> currencyStatusService(
@Query("start") String start,@Query("limit") String limit,@Query("convert") String convert
);
}
在 mainactivity 中,我要获得两个调用的结果,但我不知道该怎么做 只有一个响应我可以获得数据。 我不得不提到我在通用方法中使用来拨打电话 这里的方法:
public <T> void apiResponse(Call<T> call,ApiResponse apiResponse){
call.enqueue(new Callback<T>() {
@Override
public void onResponse(Call<T> call,Response<T> response) {
if (response.isSuccessful()){
T body = response.body();
apiResponse.success(body);
System.out.println("body = " + body);
}else{
apiResponse.error(response.message());
System.out.println("Error occurred = " + response.message() );
}
}
@Override
public void onFailure(Call<T> call,Throwable t) {
System.out.println("Api Call Failure" + t.getMessage());
}
});
}
请帮忙..