我对这段代码有疑问-
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func get(){
let url = NSURL(string: "http://www..php")
let data = NSData(contentsOfURL: url!)
values = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as!NSArray
tableView.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return values.count;
}
这个错误 线程 1 exc_bad_instruction (code=exc_1386_invop subcode=0x0)
最佳答案
试试这个-
func get()
{
if let url = NSURL(string: "https://www.hackingwithswift.com") {
do {
let JSONData = NSData(contentsOfURL: url)
do {
let JSON = try NSJSONSerialization.JSONObjectWithData(JSONData!, options:NSJSONReadingOptions(rawValue: 0))
guard let JSONDictionary :NSDictionary = JSON as? NSDictionary else {
print("Not a Dictionary")
// put in function
return
}
print("JSONDictionary! \(JSONDictionary)")
}
catch let JSONError as NSError {
print("\(JSONError)")
}
} catch {
// contents could not be loaded
}
}
else
{
// the URL was bad!
}
}
关于ios - 错误 - 线程 1 exc_bad_instruction(代码=exc_1386_invop 子代码=0x0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38889627/