我正在嘗試解析JSON但收到此錯誤:在沒有更多上下文的情況下,表達類型不明確我的代碼是:func jsonParser() { let urlPath = "http://headers.jsontest.com/" let endpoint = NSURL(string: urlPath) let request = NSMutableURLRequest(URL:endpoint!) let session = NSURLSession.sharedSession() NSURLSession.sharedSession().dataTaskWithRequest(request){ (data, response, error) throws -> Void in if error != nil { print("Get Error") }else{ //var error:NSError? do { let json:AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)) as? NSDictionary print(json) } catch let error as NSError { // error handling print(error?.localizedDescription) } } } //task.resume()}在沒有嘗試捕獲的情況下,在Xcode 6.4中可以正常工作,但是在Xcode 7中則無法工作。
- 3 回答
- 0 關注
- 702 瀏覽
添加回答
舉報
0/150
提交
取消