我必須從這個 URL https://openweathermap.org/獲取數據 ?,F在我正在使用這些 APIhttp://api.openweathermap.org/data/2.5/weatherq=(cityname)&appid=(myAPIKEY)所以我已經在下面的代碼工作這是我的基本網址:Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://api.openweathermap.org/data/2.5/") .addConverterFactory(GsonConverterFactory.create(gson)) .build();有誰知道如何將 cityName 作為參數傳遞?附言。改造2
3 回答

飲歌長嘯
TA貢獻1951條經驗 獲得超3個贊
您可以使用@Query參數來提供任何參數,如
@GET("weather")
Call<WeatherEnt> getWeatherData(@Query("q") String query,
@Query("units") String units,
@Query("appid") String appid);
并在調用此端點時在這些參數中傳遞 cityName 和其他值(就像您需要的那樣)

Qyouu
TA貢獻1786條經驗 獲得超11個贊
謝謝大家。這是一個答案。
@GET("weather") 調用 loadPhotoList(@Query("q") String cityName,@Query("appid") String appid);

白板的微信
TA貢獻1883條經驗 獲得超3個贊
你必須像這樣改變你的第二種方法:
@POST("http://api.openweathermap.org/data/2.5/weatherq={cityName}&appid=1273091827310988273")
Call<Example> loadPhotoList(@Path("cityName") String cityName);
添加回答
舉報
0/150
提交
取消