我正在使用Alamofire制作一个简单的GET请求:
Alamofire.request(.GET, url, headers: User.sharedInstance.httpHeader())
.responseJSON { request,response,result in
print(result.value)
completionHandler(responseObject: result.value as? NSDictionary, error: result.error as? NSError)
}
此行print(result.value)
打印预期的JSON结果:
▿ Optional((
{
id = 1;
name = "Texas Dropshop";
},
{
id = 2;
name = "Closepin Landromat";
}
))
▿ Some : 2 elements
▿ [0] : 2 elements
▿ [0] : 2 elements
- .0 : id
▿ [1] : 2 elements
- .0 : name
- .1 : Texas Dropshop
▿ [1] : 2 elements
▿ [0] : 2 elements
- .0 : id { ... }
▿ [1] : 2 elements
- .0 : name { ... }
- .1 : Closepin Landromat
但是当它在完成处理程序的方法中被接收时:
GetDefaultUserDropshop.execute (){ (responseObject, error) -> () in
print("responseObject = \(responseObject); error = \(error)")
}
responseObject的值为nil。我假设这与演员有关:
responseObject: result.value as? NSDictionary
但是当我转向swift时,我对如何解决它感到很遗憾。
感谢您的帮助!
答案 0 :(得分:0)
响应是数组,而不是字典