Alamofire'致命错误:在打开一个可选值时意外地发现了nil'

时间:2014-12-05 11:25:38

标签: ios iphone swift alamofire

当我在swift代码块中尝试服务器请求时,服务器响应JSON之后发生了一些错误,如下面的代码所示;

Alamofire.request(.POST, Utility.WebServiceAddress+"/ApproveOrder", parameters: parameters)
        .responseJSON
    {(request, response, JSON, error) in

        if let jsonResult: NSDictionary = JSON as? NSDictionary
        {
            if let wsResult = jsonResult[WSConstants.WSRESULT] as? NSDictionary
            {
                let resultCode = wsResult.valueForKey(WSConstants.RESULT_CODE) as Int
                if(resultCode == Utility.WS_RESULT_SUCCESS)
                {
                    self.PrepareMainItemsInBagToSetUpLocalNotifications()
                    Utility.ActivityIndicatorStopAnimating(self.activityIndicator, indicatorLabel: self.lblIndicatorMessage, viewController: self)
                    Utility.ReleaseBagAndPopToInitialViewController(self)
                }
                else
                {
                    PromptDialogs.getPromptDialogWebServiceError(self.activityIndicator, lblIndicatorMessage: self.lblIndicatorMessage, viewController: self, message: "Sipariş tablebiniz gönderilirken hata oluştu. Lütfen tekrar deneyiniz!")
                }
            }
        }
        else
        {
            PromptDialogs.getPromptDialogWebServiceError(self.activityIndicator, lblIndicatorMessage: self.lblIndicatorMessage, viewController: self, message: "Sunucudan yanıt alınamadı. Lütfen internet bağlantınızı kontrol edip yeniden deneyiniz!")
        }
    } // gives 'fatal error: unexpectedly found nil while unwrapping an Optional value' at this line, as refering Alamofire code below -> 

public func responseJSON(options: NSJSONReadingOptions = .AllowFragments, completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self {
    return response(serializer: Request.JSONResponseSerializer(options: options), completionHandler: { (request, response, JSON, error) in
        completionHandler(request, response, JSON, error)
    })
}

我将这种请求方式用于其他一些UIViewControllers。但我不明白为什么我只在这里得到这个错误?如果有必要,我可以分享更详细的代码块。

你能帮帮我吗?

祝你好运

0 个答案:

没有答案