【发布时间】:2016-04-17 11:39:56
【问题描述】:
我不熟悉在线提出请求。我正在使用 Alamofire 和 swiftyJSON 从 URL 取回数据,但它一直在崩溃,说链接返回 nil。是因为提供的链接最后不是 .json 吗? (顺便说一下,我添加的链接是假的,不能添加真正的,但结构是一样的)。
let URL = "https://www.thisurlisntreal.com/api/folder?key="12345FGhbfdgn3456fgdnf2345redfs?56"
Alamofire.request(.GET, URL).validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
print("JSON: \(json)")
}
case .Failure(let error):
print(error)
}
}
链接只有这个数据:
{"results":[{"id":1,"fromDate":"2015-03-18","toDate":"2016-04-23","url":"blabliebloe","producer":{"id":1,"name":"theproducer"}}]}
我在Alamofire.request(.GET, URL).validate().responseJSON { response in 遇到崩溃,告诉我unexpectedly found nil while unwrapping an Optional value。我用多个格式化程序和验证器检查了 JSON,一切都成功了,所以这不是问题。
更新: 我只是使用了一个不同的链接 (http://refine.taxonomics.org/gbifchecklists/reconcile?query=Crepidomanes%20minutum),这确实有效...我不知道这怎么可能,但它可能与服务器端相关吗?
【问题讨论】:
标签: json swift url alamofire swifty-json