0
我有一個線路let任務=會議上的錯誤,應用程序運行,但當json試圖加載應用程序停止並顯示在控制檯致命錯誤:意外地發現零而while展開可選的價值,我只是試圖展示的JSON在我的服務器,這個問題開始時我更新到xcode的7編碼JSON到Xcode 7與迅速2和PHP
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let jsonUrl = "{http://test.yozzibeens.com/AppTesting/JsonArray.php}"
let session = NSURLSession.sharedSession()
let shotsUrl = NSURL(string: jsonUrl)
let task = session.dataTaskWithURL(shotsUrl!)
{
(data, response, error) -> Void in
do {
let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSDictionary
print(String(jsonData["ip"]!))
} catch _ {
// Error
}
}
task.resume()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
阻止我們強制解包並使用「如果讓」和/或「讓我們讓」安全地解開你的價值觀。你的世界將立即成爲一個更好的地方。 – Moritz