// Returns the Weather Forecast today. public static WeatherAPI.RootObject makeRequest(string id) { string actionUrl = baseUrl + id + "&appid=98d8eb3d190051551f5cdbb079b6670d"; HttpWebRequest request = WebRequest.CreateHttp(actionUrl); request.Method = httpverb.GET.ToString(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); object objResponse = reader.ReadToEnd(); WeatherAPI.RootObject weat = JsonConvert.DeserializeObject <WeatherAPI.RootObject>(objResponse.ToString()); response.Close(); return(weat); }
//Displays the current weather forecast. public void CurrentWeather() { WeatherAPI.RootObject rClient = new WeatherAPI.RootObject(); rClient = RestClient.makeRequest(txtCityID.Text); cache = rClient; lblLon.Text = rClient.coord.lon.ToString(); lblLat.Text = rClient.coord.lat.ToString(); lblBase.Text = rClient.@base; lblTemperature.Text = rClient.main.temp.ToString(); lblPressure.Text = rClient.main.pressure.ToString(); lblHumidity.Text = rClient.main.humidity.ToString(); lblTempmin.Text = rClient.main.temp_min.ToString(); lblTempmax.Text = rClient.main.temp_max.ToString(); lblSealevel.Text = rClient.main.sea_level.ToString(); lblGroundlevel.Text = rClient.main.grnd_level.ToString(); lblSpeed.Text = rClient.wind.speed.ToString(); lblDeg.Text = rClient.wind.deg.ToString(); lblAll.Text = rClient.clouds.all.ToString(); lblDt.Text = rClient.dt.ToString(); lblMessage.Text = rClient.sys.message.ToString(); lblCountry.Text = rClient.sys.country.ToString(); lblSunrise.Text = rClient.sys.sunrise.ToString(); lblSunset.Text = rClient.sys.sunset.ToString(); lblId.Text = rClient.id.ToString(); lblName.Text = rClient.name; lblCod.Text = rClient.cod.ToString(); List <WeatherAPI.Weather> waw = rClient.weather; waw.ForEach(delegate(WeatherAPI.Weather weathw) { lblMain.Text = weathw.main; lblDescription.Text = weathw.description; lblIcon.Text = weathw.icon; }); }