URL query string "q={city}" must not have replace block
我无法正常工作,我尝试了其他几种变体,但仍然有某种形式的例外。
public interface WeatherInterface {
@GET("/weather?q={city}")
Call<WeatherModel> getWeather(@Query("city") String city);
}
//////
public interface WeatherInterface {
@GET("/weather")
Call<WeatherModel> getWeather(@Query("q") String city);
}
等等。
天气act。阶级
Call<WeatherModel> call = weatherInterface.getWeather("""CITYNAME""");
call.enqueue(new Callback<WeatherModel>() {
@Override
public void onResponse(Call<WeatherModel> call, Response<WeatherModel> response) {
if(response.isSuccessful()) {
**///FIRST VARIANT FAILS HERE**
city.setText(response.body().getName());
}
**///SECOND VARIANT FAILES RESPONSE**
else Log.d("No response", "RESPONSE");
}
@Override
public void onFailure(Call<WeatherModel> call, Throwable t) {
Log.d("fail", "fail");
}
});
编辑:log.d(call.request((。url((。tostring((,"呼叫请求url"(;
我也应该分享我的解决方案,我只是记录了呼叫URL。
我忘了在URL中添加我的API键。我可耻地提取了我的问题。
您可以使用此示例以示例:
public interface GitHubClient {
@GET("/users/{user}/repos")
Call<List<GitHubRepo>> reposForUser(
@Path("user") String user
);
}
有关更多样本,只需访问此网站