本文介绍了字符 0 周围的 Alamofire 无效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Alamofire.request(.GET, "url").authenticate(user: "", password: "").responseJSON() {
    (request, response, json, error) in
    println(error)
    println(json)

}

这是我对 Alamofire 的请求,对于某个请求,它有时有效,但有时我得到:

This is my request with Alamofire, for a certain request it sometime works, but sometimes i get:

Optional(Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x78e74b80 {NSDebugDescription=Invalid value around character 0.})

我已经读到这可能是由于无效的 JSON,但响应是一个静态 json 字符串,我已在 JSON 验证器中将其验证为有效.它确实包含 å ä ö 字符和一些 HTML.

I've read that this can be due to invalid JSON, but the response is a static json string that i have validated in JSON validator as valid. It does contain å ä ö characters and some HTML.

为什么我有时会收到此错误?

Why am i getting this error sometimes?

推荐答案

我也遇到了同样的问题.我尝试了 responseString 而不是 responseJSON 并且它起作用了.我猜这是 Alamofire 中的一个错误,将它与 django 一起使用.

I also faced same issue. I tried responseString instead of responseJSON and it worked. I guess this is a bug in Alamofire with using it with django.

这篇关于字符 0 周围的 Alamofire 无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:22