在Swift 2中展开复杂的JSON

时间:2015-12-27 23:24:47

标签: json swift2

我只是打了个精神障碍!我非常感谢您在解开以下内容时提供的任何帮助。

In [3]: %timeit fast_random_bool(shape)
1 loops, best of 3: 5.54 s per loop

1 个答案:

答案 0 :(得分:0)

在操场上玩!

import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

import Foundation

let url = NSURL(string: "https://webapi.tab.com.au/v1/tab-info-service/racing/dates/2015-12-28/meetings?jurisdiction=NSW")!
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
    if let urlContent = data {
        do {
            let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers)

            if let meetings = jsonResult["meetings"] as? NSArray {
                if let dateStr = meetings[0]["meetingDate"] as? String {
                    print(dateStr)
                }
            }

        } catch {
            print("Error")
        }
    }
}
task.resume()

// prints
//
// 2015-12-28

对于您需要使用的每个数据,请在此示例中继续...