swift 2 中的 NSJSONSerialization 线程中断 1.1

thread break 1.1 at NSJSONSerialization in swift 2

大家好,我最近在学习 swift 教程,目前正在研究如何使用 php 和 mysql 以及 swift。无论如何,我设法将数据保存在 mysql 数据库中。不知何故,我可以得到一个 json 对象,并向 swift 发送 return 消息,但是当我要使用 "NSJSONSerialization.JSONObjectWithData" 获取实际数据时,应用程序会崩溃。

这是目前为止的代码片段:

NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data , response, error ) -> Void in

        let dataContent = data! as NSData

        dispatch_async(dispatch_get_main_queue()){

            if error != nil{
                self.displayAlertMessage(error!.localizedDescription);
                return
            }

            print("error + \(error)" )

            print(data) // actually up to this level the code works

            do {
                //let json = try NSJSONSerialization.JSONObjectWithData(data! , options: .MutableContainers ) as? NSDictionary;

                // here thread gonna crash and shows : "Thread 1: breakpoint 1.1" message with green line

                var json = try  NSJSONSerialization.JSONObjectWithData(dataContent , options: NSJSONReadingOptions.MutableContainers) as! NSDictionary


                print(json)

                if let parseJSON:NSDictionary = json{
                    let userId = parseJSON["userId"] as? String

                    if userId != nil{

                        var myAlert = UIAlertController(title: "Alert", message: "Registration Successful", preferredStyle: UIAlertControllerStyle.Alert)

                        let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default){(action) in

                            self.dismissViewControllerAnimated(true, completion: nil )
                        }
                    }else {

                        let errorMessage = parseJSON["message"] as? String
                        if(errorMessage != nil ){

                            self.displayAlertMessage(errorMessage!)

                        }
                    }

                }


            } catch let error as NSError {
                print("json error: \(error.localizedDescription)")
            }

        }

    }).resume()
}

我卡在了 "try NSJSONSerialization.JSONObjectWithData" 行。谁能帮我解决这个问题?

感谢大家的大力帮助

如果显示线程中断 1.1,则表示您设置了断点并且调试器在该行暂停。如果您查看断点导航器(command-7 是快捷方式),您是否看到该行代码的断点?行号旁边的编辑器的排水沟中可能还有一个蓝色的小箭头。