如何在单个改造请求中传递多个值

How to pass multiple value in a single in retrofit request

我在我的应用程序中使用了 Retrofit2 和 RxJava。我必须传递与单个键对应的多个值。以下是我的要求 URL

https://api.openweathermap.org/data/2.5/onecall?lat=28.46&lon=77.03&exclude=hourly,alerts,minutely&appid=01s

现在在上面 URL 中有 exclude 键,多个参数在其中传递如何在我的界面中添加这些参数。下面是我的界面。

ApiService.class

interface ApiService {

@GET("data/2.5/onecall")
fun getCurrenttemp(@Query("lat") lat:String,
                   @Query("lon") lon:String,
                   @Query("exclude") exclude:String,
                   @Query("appid") appid:String):Observable<Climate>

}

如何提出所需的请求?

正如 One Call API 的 documentation 中的 exclude 参数部分所述,

By using this parameter you can exclude some parts of the weather data from the API response. It should be a comma-delimited list (without spaces).

所以它不是要求多个值,而是一个带有 comma-separated 选项标签的字符串值,它们之间没有空格。只需将“hourly,alerts,minutely”放入一个字符串变量中并通过您的界面传递您在以下代码行 @Query("exclude") exclude:String 中已有的字符串,它应该可以工作:

var excludeParamToPass = "hourly,alerts,minutely"

来自同一个 reference 的 API 的一个示例:

https://api.openweathermap.org/data/2.5/onecall?lat=33.441792&lon=-94.037689&exclude=hourly,daily&appid={API key}