Last active
July 22, 2017 12:20
-
-
Save DamianRyse/0ab9d04496da5865d5da1316d1ec9ac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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