Alamofire - 发送和接收JSON时ResponseSerializationFailed

时间:2018-04-02 08:30:07

标签: ios swift network-programming alamofire

我将JSON对象发送到我的API并以JSON格式接收响应。 以下是PostMan中工作API的快照 enter image description here

但是当我在Alamofire发送请求时,我收到 responseSerializationFailed 错误。以下是代码。

self.url = URL(string: "http://xyzxyz/api/CheckQRCode")!

let imageData:NSData = UIImagePNGRepresentation(image)! as NSData
let strBase64:String = imageData.base64EncodedString(options: .lineLength64Characters)

let parameters: [String:Any] = [
            "QrCode": carIdentifier,
            "qrCodeImageDumy": strBase64
        ]
let headers: HTTPHeaders = [
            "Content-Type":"application/json",
            "Accept":"application/json"
        ]

Alamofire.request(self.url!, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
            .responseJSON { (response) -> Void in

            switch response.result {
            case .success:
                guard let rawJson = response.result.value as? [String: Any] else {
                    print("Received Malformed data from server")
                    return
                }
                let formattedJson = JSON(rawJson)

            case .failure(let error):
                errorBlock(error)
            }
        }

但我收到以下错误。 in xcode 请帮忙!

0 个答案:

没有答案