我用这Alamofire请求并返回一个JSONAlamofire请求响应?
let todoEndpoint: String = "https://api.abc.com/api/v3/products?pid=uid8225&format=json&&offset=0&limit=10"
Alamofire.request(todoEndpoint)
.responseJSON { response in
guard let json = response.result.value as? [String: Any] else {
print("didn't get todo object as JSON from API")
print("Error: \(response.result.error)")
return
}
print(json)
}
现在我有做的循环,我想用这个JSON的价值,但我得到:
错误:使用未解决的标识符的JSON ?
do {
for (index,subJson):(String, JSON) in json {
print("Index :\(index) Title: \(subJson)")
} catch
{
print("there was an error")
}
如前所述:
https://github.com/Alamofire/Alamofire#response-string-handler “的请求的结果是唯一的响应盖的范围内可在响应或数据的任何执行队伍从服务器接收到必须做在答复结束之内“。
如何在响应关闭范围外使用此json值?
能否请你建议
有没有完成处理程序,我需要写和怎么能做到呢?
感谢
[使用新的Swift 3和Alamofire解析JSON](http://stackoverflow.com/questions/39468516/parsing-json-using-the-new-swift-3-and-alamofire) – 2017-04-12 12:13:50
GS ,您是否尝试搜索解决方案,因为此问题已被询问为超过30多个主题:https://www.google.se/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q= alamofire + json + response + swift + stackoverflow – 2017-04-12 12:14:35
你应该在后卫后面跑,即'guard let else {...} HERE'。目前你在'json'不存在的范围内执行它 – Honey