我在嘗試從Google博客解析某些JSON時出錯。在Swift中解析json時出錯
我收到的錯誤是
'Invalid conversion from throwing function of type '(_, _, _) throws -> Void' to non-throwing function type '(NSData?, NSURLResponse?, NSError?) -> Void'
我身邊有一派,我知道這是什麼做追趕的錯誤,但我想不出它到底是什麼,任何幫助將不勝感激:
import UIKit
import CoreData
class MasterViewController: UITableViewController {
var detailViewController: DetailViewController? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL(string: "https://www.googleapis.com/blogger/v3/blogs/10861780/posts?key=AIzaSyBwmI4AzMnBmr7oSVeL0EHdzMjXV1aATnQ")
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in
if error != nil {
print(error)
} else {
//print(NSString(data: data!, encoding: NSUTF8StringEncoding))
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
if jsonResult.count > 0 {
if let items = jsonResult["items"] as? NSArray {
for items in items {
print(items)
}
添加「抓讓誤差NSError { 打印(error.localizedDescription) }」 – Ragul
如果有這樣的在右括號後的底部剛過打印(項目)增加?如果不是我應該添加這個嗎?謝謝! –
add do {} – Ragul