Ghost Ghost - 1 year ago 238
JSON Question

Using yahoo weather Api

I am using yahoo weather api and getting result using this link:*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22london%22)&format=json

Now I want to using this url with retrofit. So please tell me how to change the city by passing query.

Thank you

Answer Source

It would end up being something like this:

public interface WeatherService {
   Call<String> getWeather(@Query("q") String query);


Then create the object like this:

Retrofit retrofit = new Retrofit.Builder()

      WeatherService wService = retrofit.create(WeatherService.class);

And run it like this:

String query = "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"Leeds\")&format=json";

Call<String> weather = wService.getWeather(query);
         try {
            Response<String> resp = weather.execute();

You should change the ConverterFactory to json and properly parse the weather output.

I have not tested this, just giving you an idea of how to use the Retrofit query.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download