这是我的代码来获取JSON,它与我在其他问题上找到的这个URL一起工作:http://binaenaleyh.net/dusor/。 但是,当我使用它与此网址:http://www.netcampus.fr/api/schools,它根本没有工作。我有一个错误说:“exc_breakpoint(code = exc_i386_bpt subcode = 0x0)”在Swift中获取JSON
是我的代码错了,还是它的JSON数据?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var myData:NSData = getJSON("http://www.netcampus.fr/api/schools")
println(myData) // show me data
var myDict:NSDictionary = parseJSON(myData)
println(myDict)
}
func getJSON(urlToRequest: String) -> NSData{
return NSData(contentsOfURL: NSURL(string: urlToRequest))
}
func parseJSON(inputData: NSData) -> NSDictionary{
var error: NSError?
var boardsDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary // error here
return boardsDictionary
}
}
乘坐齿赚取至少一一点关于JSON。有了一点JSON知识,人们可以看到一个顶级数组,另一个顶级字典。作为软件开发人员需要了解您编写的代码**和**从其他人处获得的代码。 – zaph