简体   繁体   English

Rest Api 在 ZE84E30B9390CDB468DB6DB2C9DZ7 中使用 Retrofit

[英]Rest Api using Retrofit in Android

My code我的代码

public interface ApiInterface 

{

    @GET("convert?q=USD_{currency}&compact=ultra&apiKey="+API_KEY)
    Call<Currency> getRates(@Path("currency") String currency );
}

But I am getting the following Error:但我收到以下错误:

java.lang.IllegalArgumentException: URL query string "q=USD_{currency}&compact=ultra&apiKey=9b1166408fb8799dee9e" must not have replace block. For dynamic query parameters use @Query.

make your interface like this:让你的界面像这样:

@GET("convert")
Call<Currency> getRates(@Query("q") String query, @Query("compact") String compact, @Query("apiKey") String apiKey);

You can call it like this way:你可以这样称呼它:

String mCurrency="$";

Call<Currency> call = mApiInterface.getRates("USD_"+mCurrency, "ultra", API_KEY);

You need to put your query parameters inside of the interface like this:您需要将查询参数放在界面中,如下所示:

@GET("convert")
Call<Currency> getRates(@Query("q") String currency, @Query("compact") String compact, @Query("apiKey") String apiKey);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM