/// <summary> /// Get data from OpenWeather Map and convert it from JSON /// </summary> /// <param name="CityName"></param> public void Get_n_Convert(string CityName = "Moscow") { string url = $"http://api.openweathermap.org/data/2.5/weather?q={CityName}&&units=metric&lang=ru&appid=c04fad8e5e16ffab2117b8474d754dc5"; try { string response; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream())) { response = streamReader.ReadToEnd(); } WeatherResponse weatherResponse = JsonConvert.DeserializeObject <WeatherResponse>(response); DictFill(weatherResponse); } catch { MessageBox.Show("This city does not exist. Try again"); } }
/// <summary> /// Fill all dictionaries /// </summary> /// <param name="weatherResponse"></param> private void DictFill(WeatherResponse weatherResponse) { WeatherData_REfill(weatherResponse); W_Main_REfill(weatherResponse); WeatherList_REfill(weatherResponse); }