Skip to content

Instantly share code, notes, and snippets.

@DamianRyse
Last active July 22, 2017 12:20
Show Gist options
  • Save DamianRyse/0ab9d04496da5865d5da1316d1ec9ac7 to your computer and use it in GitHub Desktop.
Save DamianRyse/0ab9d04496da5865d5da1316d1ec9ac7 to your computer and use it in GitHub Desktop.
public async static Task<string> GetWeather(string City)
{
HttpClient client = new HttpClient();
const string openweathermap_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
dynamic JSON = client.GetStringAsync("http://api.openweathermap.org/data/2.5/weather?q=" + City.ToLower() + "&APPID=" + openweathermap_id + "&units=metric").Result;
// Be sure, there is no error.
try
{
decimal temperature = JSON["main"]["temp"];
string city = JSON["name"];
return "In " + city + " hat es momentan " + temperature.ToString("0.00") + "°C, die Luftfeuchtigkeit beträgt " + JSON["main"]["humidity"] + "%";
}
catch (Exception ex)
{
try
{
return JSON["cod"];
}
catch
{
return ex.InnerException.Message;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment