1

当我尝试在我的 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。但我不明白为什么我只在这里收到这个错误?如果你有需要,我可以分享更详细的代码块。

你可以帮帮我吗 ?

此致

4

0 回答 0