Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误域= NSCocoaErrorDomain代码= 3840 [英] Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840

查看:629
本文介绍了Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误域= NSCocoaErrorDomain代码= 3840的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究迅速的项目,并使用Alamofire调用网络服务。
但是,在调用post方法时,出现以下错误。

I am working on swift project and calling webservice with Alamofire. But, while calling post method, I am getting following error.

Header file :

let accessTokenHeaderFile = [
    "Accept": "application/json",
    "Content-Type" :"application/json",
    "X-TOKEN" : UtilityClass.sharedInstance.accessTokenString
]

        Alamofire.request(urlString, method: .post, parameters: params as? [String:Any], encoding: JSONEncoding.default, headers: accessTokenHeaderFile).responseJSON { response in
          requestVC.removeLoader()
            switch (response.result) {
            case .success:
                if response.result.value != nil{
                    completionHandler (response.result.value)
                }
                break
            case .failure(let error):
                failureHandler (error as NSError?)
                break
            }
        }

错误为

FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))

有人可以建议我,如何解决这个问题,我尝试使用谷歌搜索,但是无论我发现什么答案都帮不了我。

Can anyone suggest me, how to fix this, I tried googling, but whatever I found the answers not helped me.

推荐答案

错误3840表示响应来自服务器不是有效的JSON字符串。因此,您可以检查 parameters键值可能是分配错误的原因,因为 responseString类似于responseJSON

Error of 3840 saying that the response from server is not a valid JSON string. So you can check you parameters key value may be it’s wrong assign because similar of responseString instead of responseJSON.

这篇关于Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误域= NSCocoaErrorDomain代码= 3840的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆