I am trying to incorporate Wunderground into my current project. I have looked at several api tutorials, but I can't seem to figure out how to access a certain part of the API. For example, this is sort of what the API looks like:
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"history": 1
}
}
,
"history": {
"date": {
"pretty": "August 9, 2015",
"year": "2015",
"mon": "08",
"mday": "09",
"hour": "12",
"min": "00",
"tzname": "America/Los_Angeles"
},
Let's say I wanted to return only the hour from the API. How would I do that?
A way to parse JSON without frameworks:
typealias JSONdic = [String: AnyObject]
NSURLConnection.sendAsynchronousRequest(NSURLRequest(URL: nsUrl), queue: NSOperationQueue.mainQueue(), completionHandler: { (_, data, _) -> Void in
if let data = data, json = data as? JSONdic, history = json["history"] as? JSONdic, hour = history["hour"] as? String {
println(hour)
}