//NSURLSession
/*
创建一个session ->创建一个task -> 启动task -> 处理回调
*/
//http://www.douban.com/j/app/radio/channels
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithURL(NSURL(string: "http://www.douban.com/j/app/radio/channels")!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
//回调处理
let json = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as! NSDictionary
print("json:(json)")
})
dataTask.resume()
/*
创建一个session ->创建一个task -> 启动task -> 处理回调
*/
//http://www.douban.com/j/app/radio/channels
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithURL(NSURL(string: "http://www.douban.com/j/app/radio/channels")!, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
//回调处理
let json = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as! NSDictionary
print("json:(json)")
})
dataTask.resume()
}