alamofire.error Code =

编程入门 行业动态 更新时间:2024-10-25 14:34:27
本文介绍了alamofire.error Code = -6006"JSON无法序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

从事此工作有点失败.我有一个转到UIButton的函数,仅用于对使用所有JSON的rails api执行alamofire调用.

Been working on this for a bit with no success. I have a function that goes to a UIButton solely to perform alamofire calls to my rails api which uses all JSON.

我正在使用Swift 2,Alamofire 3,XCode 7&我的api的Rails 4部署到了Heroku

I'm using Swift 2, Alamofire 3, XCode 7 & Rails 4 for my api which is deployed to Heroku

当我关闭该功能时,我总是收到此错误:

I keep getting this error when I fire off the function :

alamofire.error代码= -6006"JSON无法序列化.输入数据为nil或零长度.

alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero length.

这是我的代码:

@IBAction func Save(sender: AnyObject) { let postsEndpoint: String = "APIURL" let parameters = [ "users": [ "name": "James McHarty", "avatar": "Some binary data", "post": [ "title": "First Test Post", "body": "This is the first test post for the API", "liked": "8", //will make INT later "img": "more binary data" ] ] ] Alamofire.request(.POST, postsEndpoint, parameters: parameters, encoding: .JSON) .responseJSON { response in guard response.result.error == nil else { // got an error in getting the data, need to handle it print(response.result.error!) return } } print("func'd") }

推荐答案

这不是Alamofire或快速错误,服务器返回的响应不是JSON格式.您可以打印出响应数据并检查其中有什么问题.

This is not Alamofire or swift error, The response returned by the server is not in the JSON format. you can print out response data and check what is wrong in this.

尝试使用此代码打印出我们的服务器数据,以轻松识别错误并解决.

try this code to print out our server data to easily identifying to error and resolve this.

Alamofire.request("Your url").responseJSON(completionHandler: { (response) in switch response.result { case .success(let value): break case .failure(let error): print("\n\n===========Error===========") print("Error Code: \(error._code)") print("Error Messsage: \(error.localizedDescription)") if let data = response.data, let str = String(data: data, encoding: String.Encoding.utf8){ print("Server Error: " + str) } debugPrint(error as Any) print("===========================\n\n") } })

更多推荐

alamofire.error Code =

本文发布于:2023-11-26 17:30:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:alamofire   error   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!