Alamofire无法正常工作 – Tuple发行不同数量的元素

使用Xcode 7.1

在Alamofire responseJSON请求中我不能放4个参数。 下面是代码

let url2 = "https://httpbin.org/get" Alamofire.request(.GET, url2).responseJSON{ request, response, JSON, error in print(JSON) } 

我得到这个错误:元组types'(NSURLRequest?,NSHTTPURLResponse?,结果)'(又名'(可选,可选,结果)')和'(_,_,_,_)'有不同数量的元素(3与4)

如果我从responseJSON中删除“ 错误 ”参数并运行它…应用程序生成,但没有JSON打印在控制台上..

  let url2 = "https://httpbin.org/get" Alamofire.request(.GET, url2).responseJSON{ request, response, JSON in print(JSON) } 

控制台输出

在这里输入图像说明

没有打印JSON。 如果您从代码中访问示例url ,您将看到JSON。

我遵循GitHub的指示,但不工作

Alamofire v1.x有四个参数给responseJSON闭包。 Alamofire v2.x有三个参数。 Alamofire v3.x现在使用单个参数调用闭包: Response

 Alamofire.request(.GET, url2).responseJSON { response in switch (response.result) { case .Success(let value): print(value) case .Failure(let error): if let data = response.data, let string = String(data: data, encoding: NSUTF8StringEncoding) { print(string) } print(error) } } 

或者,您可以使用isFailureisSuccessisFailurevaluedataerror computed属性,例如:

 Alamofire.request(.GET, url2).responseJSON { response in print(response.result.value) } 

[这已经更新为Alamofire 3语法。 如果您需要Alamofire 2语法,请参阅此问题的修订历史logging 。]

Github上的文档还没有更新到最新版本的Alamofire。

要查看Rob指出的属性,请检查框架的源代码。