Alamofire4与JSONResponseSerializer和HTTPURLResponse Swift 3.0有关

自从我更新了Alamofire后我得到了错误: Type Request没有成员JSONResponseSerializer并且无法调用非函数类型HTTPURLResponse的值

我已经将Response切换到DataResponse,但我仍然收到错误。

在此处输入图像描述

码:

extension Alamofire.Request { func responseUserEventsArray(_ completionHandler: @escaping (DataResponse) -> Void) -> Self { let responseSerializer = DataResponseSerializer { request, response, data, error in guard error == nil else { return .failure(error!) } guard let responseData = data else { return .failure(AFError.responseSerializationFailed(reason: .inputDataNil)) } let JSONResponseSerializer = Request.JSONResponseSerializer(options: .allowFragments) let result = JSONResponseSerializer.serializeResponse(request, response, responseData, error) switch result { case .Success(let value): let json = JSON(value) let wrapper = UserEventsWrapper() wrapper.next = json["eventhistory"]["next_page_url"].stringValue wrapper.previous = json["eventhistory"]["prev_page_url"].stringValue wrapper.count = json["eventhistory"]["total"].intValue var allUserEvents:Array = Array() print(json) let results = json["eventhistory"]["data"] print(results) for jsonAds in results { print(jsonAds.1) let adsData = UserEvents(json: jsonAds.1, id: Int(jsonAds.0)) allUserEvents.append(adsData) } wrapper.usereventsitems = allUserEvents return .success(wrapper) case .Failure(let error): return .Failure(error) } } return response(responseSerializer: responseSerializer,completionHandler: completionHandler) } } 

EDITED


更改

Request.JSONResponseSerializerDataRequest.jsonResponseSerializer

extension Alamofire.Request extension Alamofire.DataRequest – Mat0

.success.failure – FranMowinckel