【发布时间】:2016-01-11 09:11:37
【问题描述】:
我正在使用 alamofire 调用 api。但在这个特定的 api 中,我得到 nil 值作为响应。实际上,当我在浏览器中点击我的 api 时,它工作得很好。
这是我的代码
func web()
{
request(.GET, "http://www.horecasupply.nl/AJAX?function=appStructure", parameters: nil, encoding: .JSON).responseJSON { (response : Response<AnyObject, NSError>) -> Void in
if response.result.value != nil {
print(response.result.value)
}
}
}
得到 nil 值,当我打印时,它会显示给我
Printing description of response.result.Failure:
Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1."
UserInfo={NSDebugDescription=Invalid value around character 1.}
编辑 1:: 尝试了 responsestring 而不是 responsejson。 但是得到不同类型的响应,那么我该如何转换呢?
\r\n\r\n\r\n\r\n\r\n DD_belatedPNG.fix(\'img, .png_bg\'); //修复任何或 .png_bg 背景图像 \r\n\r\n\r\n\r\n-->\r\n\r\n\ r\n\r\n\r\n\r\n \r\n\r\n")
【问题讨论】:
-
尝试使用
responseString代替responseJsonAlamofire invalid value around character 0 -
通过使用responsestring得到这种响应\r\n\r\n\r\n\r\n\r\n DD_belatedPNG.fix(\'img, .png_bg \'); //修复任何或 .png_bg 背景图像 \r\n\r\n\r\n\r\n-->\r\n\r\n\ r\n\r\n\r\n\r\n \r\n\r\n")
-
我运行了你发布的相同代码并且它工作正常。我得到与浏览器相同的响应。
-
你使用的是哪个xcode?呸呸呸
-
您的代码 sn-p 对我有用 (screenshot)。
标签: ios swift swift2 ios9 alamofire