我试图访问页面上的数据https://api.myjson.com/bins/4xi1h 但它返回零而不是数据。我不知道为什么。JSON返回零Swift
当我用一些其他JSON API替换URL时,此代码返回数据。
var restUrl: NSURL = NSURL(string: "https://api.myjson.com/bins/4xi1h")!
let jsonUrlData = NSData (contentsOfURL: restUrl)
println(jsonUrlData)
if jsonUrlData != nil{
var dictionary : NSDictionary = NSJSONSerialization.JSONObjectWithData(jsonUrlData!, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
println(dictionary)}
我看不到你在哪里试图解析JSON? – Anton
该字典已正确填充,请参阅我的[截图](https://www.evernote.com/shard/s89/sh/8a3e1d89-f402-4279-b0f3-1759be24a3a3/61f49c7e9adbd1358f4285c3b481715a/deep/0/dfsdsdf.playground.png )。我只是不得不使用'as! NSDictionary'而不是'NSDictionary'(注意'!')。那么你肯定有另外一种问题。 – Moritz
@ericd这似乎是一个Swift 1.2错误,OP可能会也可能不会使用。 – AstroCB