在解包可选值 JSON 序列化时发现 nil


Found nil while unwrapping optional value JSON Serialization

我执行一个NSURLSession从php获取数据,这是一个JSON。当我NSJSONSerialization并将其存储为NSArray时,一切正常,但是当我尝试访问它的一个元素以将其放入表视图中时,它会崩溃,并在解开可选值时发现错误 nil。它返回的 JSON 如下所示:

[
   {
   "title":"data",
   "value":"data"
   }, ...
]

我用来获取值的代码是:

self.arrayJSON[indexPath.row]["title"]

当我在 Xcode 控制台中尝试此操作时,返回以下内容:

▿ Optional(some data)
 - Some : some data

编辑:

JSON 解析代码:

let task = session.dataTaskWithRequest(request) { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
        do {
            let responseJSON : NSArray = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! NSArray
            self.arrayJSON = NSMutableArray(array: responseJSON)
            dispatch_async(dispatch_get_main_queue()) {
                self.listaAnuncios.reloadData()
            }
        } catch {
            print("json error")
        }
    }
    task.resume()

我发现了问题!这不是因为访问元素,而是因为单元格为零。我正在使用这个:

let cell : CustomCell = CustomCell()

我为此更改了它:

let cell = tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as! CustomCell