本文介绍了iOS:JSONObjectWithData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Xcode更新为版本7,并尝试重用旧代码:

I updated Xcode to version 7 and tried reusing my old code:

let downloadTask : NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(dataURL!, completionHandler: { (location: NSURL?, response: NSURLResponse?, error: NSError?) -> Void in

let dataObject = NSData(contentsOfURL: location!)
let dataDictionary : NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
})

在最后一行,我现在遇到错误:调用中额外的参数'error'

On the last line I'm now getting error: Extra argument 'error' in call

尽管在NSJSONSerialization类参考中,该方法包含error参数.

Though in the NSJSONSerialization Class reference the method contains the error argument.

在这方面我还是一个新手,如果有人可以向我解释发生了什么以及如何解决这个问题,我将非常感激.

I'm still kinda newbie in this, if someone can please explain me what's going on and how to solve this I will be very grateful.

谢谢.

推荐答案

尝试一下:

let dataObject = NSData(contentsOfURL: location!)
do {
    let dataDictionary : NSDictionary = try NSJSONSerialization.JSONObjectWithData(dataObject!, options: []) as NSDictionary
} catch _ {
    dataObject = nil
}

这篇关于iOS:JSONObjectWithData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:32