private void Form1_Load(object sender, EventArgs e) { string url = "http://api.openweathermap.org/data/2.5/weather?q=Moscow&appid=1eaa4e8c2e0d05fef8140b2d11fbf888&units=metric"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader reader = new StreamReader(res.GetResponseStream()); string response = reader.ReadToEnd(); richTextBox1.Text = response; WeatherResponse wr = JsonConvert.DeserializeObject <WeatherResponse>(response); lCity.Text = wr.Name; lTemp.Text = wr.Main.temp.ToString(); }
static void Main(string[] args) { string key = "fd7b782958da8a7b5199332d283f87d3"; string city = ""; Console.WriteLine("Vvedite nazvanie goroda v kotorom hotite yznat` temperatyry. \n"); city = Console.ReadLine(); Console.WriteLine(); string url = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&appid=" + key; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream())) { string result = streamReader.ReadToEnd(); WeatherResponse weatherResponse = JsonConvert.DeserializeObject <WeatherResponse>(result); Console.WriteLine("Temperature in " + weatherResponse.Name + ": " + weatherResponse.Main.Temp + "°C \n"); } Console.ReadLine(); }