Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何正确设置改装参数_Android_Retrofit2_Android Developer Api_Rx Java2 - Fatal编程技术网

Android 如何正确设置改装参数

Android 如何正确设置改装参数,android,retrofit2,android-developer-api,rx-java2,Android,Retrofit2,Android Developer Api,Rx Java2,我正在尝试使用改型2创建天气应用程序,现在我很难正确设置通话 以下是有效的URL: http://api.openweathermap.org/data/2.5/weather?q=London&APPID=MY_API_KEY 所以,我有我的API密钥,基本URL是:。。这是我的改装服务中的方法: @GET("/data/2.5/weather?q={city}/&APPID={api}") Observable<WeatherResponse>

我正在尝试使用改型2创建天气应用程序,现在我很难正确设置通话

以下是有效的URL:

http://api.openweathermap.org/data/2.5/weather?q=London&APPID=MY_API_KEY
所以,我有我的API密钥,基本URL是:。。这是我的改装服务中的方法:

    @GET("/data/2.5/weather?q={city}/&APPID={api}")
    Observable<WeatherResponse> getWeather(@Path("city") String city, @Path("api") String api);
@GET(“/data/2.5/weather?q={city}/&APPID={api}”)
可观测的getWeather(@Path(“city”)字符串city,@Path(“api”)字符串api);
我得到的错误是:

java.lang.IllegalArgumentException:URL查询字符串“q={city}/&APPID={api}”不能有替换块。对于动态查询参数,请使用@query

所以我试着这样:

@GET("/data/2.5/weather?{city}/&APPID={api}")
Observable<WeatherResponse> getWeather(@Query("city") String city, @Path("api") String api);
@GET(“/data/2.5/weather?{city}/&APPID={api}”)
可观测的getWeather(@Query(“city”)字符串city,@Path(“api”)字符串api);
我得到了同样的错误。。。有人知道这是怎么回事,我的url有什么问题吗?

这样做:

@GET("/data/2.5/weather")
Observable<WeatherResponse> getWeather(@Query("q") String city, @Query("APPID") String api);
@GET(“/data/2.5/weather”)
可观测的getWeather(@Query(“q”)字符串city,@Query(“APPID”)字符串api);
无需在改装中手动输入参数值-您只需告诉它什么是参数名称

这样做:

@GET("/data/2.5/weather")
Observable<WeatherResponse> getWeather(@Query("q") String city, @Query("APPID") String api);
@GET(“/data/2.5/weather”)
可观测的getWeather(@Query(“q”)字符串city,@Query(“APPID”)字符串api);

无需在改装中手动输入参数值-您只需告诉它什么是参数名称

现在我遇到了以下错误:java.lang.IllegalArgumentException:路径参数不能出现在查询之后。。。您知道为什么路径不能在查询之后出现吗?对不起,我的错误-在您的请求中应该只有查询注释。当您希望在请求中间插入参数时,使用路径(例如,一些ID:<代码> /GET/Huff/1 /INFO < /代码> - 1是ID,并且在改装中将使用PATH(“ID”):<代码> /GET/Huff/{ID}。/信息man您用@Path参数保存了我的周末,以便在中间插入请求。现在我收到以下错误:java.lang.IllegalArgumentException:路径参数不能在查询之后出现。。。您知道为什么路径不能在查询之后出现吗?对不起,我的错误-在您的请求中应该只有查询注释。当您想要在请求中间插入参数时,例如使用一些ID:<代码> /GET/Upvs/1 /INFO < /代码> - 1是ID,并且在改型中将使用路径(“ID”):<代码> /GET/Huff/{ID}/INFO < /Cord>您用@ PATH参数保存了我的周末,以在中间插入请求。