public string getCurrentWeatherAsJSON() { HttpWebRequest apiRequest = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey + "&units=metric") as HttpWebRequest; string apiResponse = ""; using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()); apiResponse = reader.ReadToEnd(); } Model.WeahterCurrent.JSONHelper.RootObject rootObject = JsonConvert.DeserializeObject <Model.WeahterCurrent.JSONHelper.RootObject>(apiResponse); return(apiResponse); }
public void updateWeatherCurrent() { HttpWebRequest apiRequest = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey + "&units=metric") as HttpWebRequest; string apiResponse = ""; using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()); apiResponse = reader.ReadToEnd(); } Model.WeahterCurrent.JSONHelper.RootObject rootObject = JsonConvert.DeserializeObject <Model.WeahterCurrent.JSONHelper.RootObject>(apiResponse); //Location weatherCurrent.location.coord.lat = rootObject.coord.lat; weatherCurrent.location.coord.lon = rootObject.coord.lon; weatherCurrent.location.nameCountry = rootObject.sys.country; weatherCurrent.location.idCity = rootObject.id; //City ID weatherCurrent.location.nameLocality = rootObject.name; //Name Ortschaft //Wheather weatherCurrent.weather.description = rootObject.weather[0].description; weatherCurrent.weather.icon = rootObject.weather[0].icon; weatherCurrent.weather.id = rootObject.weather[0].id; weatherCurrent.weather.main = rootObject.weather[0].main; weatherCurrent.weather.clouds = rootObject.clouds.all; weatherCurrent.weather.humidity = rootObject.main.humidity; weatherCurrent.weather.pressure = rootObject.main.pressure; weatherCurrent.weather.temperatur = rootObject.main.temp; weatherCurrent.weather.temperatur_max = rootObject.main.temp_max; weatherCurrent.weather.temperatur_min = rootObject.main.temp_min; weatherCurrent.weather.wind.deg = rootObject.wind.deg; weatherCurrent.weather.wind.speed = rootObject.wind.speed; weatherCurrent.weather.sunrise = UnixTimeStampToDateTime(rootObject.sys.sunrise); weatherCurrent.weather.sunset = UnixTimeStampToDateTime(rootObject.sys.sunset); weatherCurrent.weather.visibilityMeter = rootObject.visibility; weatherCurrent.weather.dt = UnixTimeStampToDateTime(rootObject.dt); // Time Weatherdata }