コード例 #1
0
        private void buttonGetInfo_Click(object sender, EventArgs e)
        {
            string url = "http://api.openweathermap.org/data/2.5/weather?q=" + textBoxCity.Text + "&appid=4e48950e61aa189901c61ad99f57a27a&units=metric";

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
            {
                textBoxServerInfo.Text = streamReader.ReadToEnd();
            }

            WeatherInfo     weatherInfo     = JsonConvert.DeserializeObject <WeatherInfo>(textBoxServerInfo.Text);
            WeatherInfoData weatherInfoData = new WeatherInfoData(weatherInfo);

            weathers.Add(weatherInfoData);

            // labelTemp.Text = weatherInfo.Main.Temp.ToString();
        }
コード例 #2
0
 private void listBoxCities_SelectedIndexChanged(object sender, EventArgs e)
 {
     WeatherInfoData weatherInfo = (WeatherInfoData)listBoxCities.SelectedItem;
     // labelTemp.Text = weatherInfo.Main.Temp.ToString();
     // textBoxServerInfo.Text = weatherInfo.Name + " " + weatherInfo.Main.Temp + " " + weatherInfo.Main.Pressure;
 }