Skip to content

Instantly share code, notes, and snippets.

@lbehnke
Last active August 29, 2015 14:10
Show Gist options
  • Save lbehnke/09eddd957e5fd13d6026 to your computer and use it in GitHub Desktop.
Save lbehnke/09eddd957e5fd13d6026 to your computer and use it in GitHub Desktop.
Parse JSON document returned from web service.
let temperature = (jsonResult["list"]? as NSArray)[0]["main"] as NSDictionary)["temp"] as? Double
let celsius = round(tempResult - 273.15)
if let city = (jsonResult["city"]? as? NSDictionary) {
if let country = (city["country"] as? String) {
println("Country :" + country );
}
}
{
city = {
coord = {
lat = "37.323002";
lon = "-122.032181";
};
country = US;
id = 5341145;
name = Cupertino;
population = 0;
};
cnt = 41;
cod = 200;
list = (
{
clouds = {
all = 92;
};
dt = 1417726800;
"dt_txt" = "2014-12-04 21:00:00";
main = {
"grnd_level" = "988.64";
humidity = 100;
pressure = "988.64";
"sea_level" = "1027.02";
temp = "292.23";
"temp_kf" = "5.44";
"temp_max" = "292.23";
"temp_min" = "286.785";
};
rain = {
3h = "7.5";
};
sys = {
pod = d;
};
weather = (
{
description = "moderate rain";
icon = 10d;
id = 501;
main = Rain;
}
);
wind = {
deg = "125.502";
speed = "1.32";
};
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment