private async void btnCerca_Click(object sender, RoutedEventArgs e) { try { HttpClient client = new HttpClient(); string result = await client.GetStringAsync(new Uri(@"http://api.wunderground.com/api/6a5d66636582ea3b/conditions/q/IT/" + tbxCitta.Text + ".json")); JsonMeteo Meteo = JsonConvert.DeserializeObject <JsonMeteo>(result); lblNomeCitta.Content = "Citta: " + Meteo.current_observation.display_location.city.ToString(); lblAltitudine.Content = "Altitudine: " + Meteo.current_observation.display_location.elevation.ToString() + "Mt"; lblLatitudine.Content = "Latitudine: " + Meteo.current_observation.display_location.latitude.ToString() + "°"; lblLongitudine.Content = "Longitudine: " + Meteo.current_observation.display_location.longitude.ToString() + "°"; lblTemperatura.Content = "Temperatura: " + Meteo.current_observation.temp_c.ToString() + "°C"; lblVento.Content = "Vento: " + Meteo.current_observation.wind_kph.ToString() + "Km/h"; lblPressione.Content = "Pressione: " + Meteo.current_observation.pressure_mb.ToString() + " Millibar"; lblUmidita.Content = "Umidità: " + Meteo.current_observation.relative_humidity.ToString(); if (Convert.ToInt32(Meteo.current_observation.UV) < 1) { lblUv.Content = "Raggi UV: Non presenti"; } else { lblUv.Content = "Raggi UV: " + Meteo.current_observation.UV.ToString(); } imgMeteo.Source = new BitmapImage(new Uri(Meteo.current_observation.icon_url)); } catch (Exception I) { MessageBox.Show("Citta non valida --> " + I.Message); } }
private async Task btnCerca_ClickAsync(object sender, RoutedEventArgs e) { HttpClient client = new HttpClient(); string result = await client.GetStringAsync(new Uri(@"http://api.wunderground.com/api/1381805c071d61f2/conditions/q/IT/" + txtCitta.Text + ".json")); JsonMeteo Meteo = JsonConvert.DeserializeObject <JsonMeteo>(result); }