快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值".

编程入门 行业动态 更新时间:2024-10-24 01:52:18
本文介绍了快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在解决Swift Alamofire POST请求(登录用户)时遇到此错误消息.

I am having trouble fixing this error message on my Swift Alamofire POST request (to login a user).

'3840'字符1周围的值无效".

'3840' "Invalid value around character 1."

我已经导入了Foundation, Alamofire , SwiftyJson .没有授权限制(没有Oauth等).更改Post(例如,使用其他参数和值的另一个端点)但将其余代码/格式保持不变时,我也收到相同的错误消息.在我的drupal7 REST服务器的'definitions'上,它将端点列出为/rest/user/login,并将参数列出为'username'和'password'字符串(如我所用).

I have imported Foundation, Alamofire, SwiftyJson. There are no authorisation restrictions (no Oauth etc). I'm also getting the same error message when I change the Post (eg to another endpoint, with other parameters and values) but keep the rest of the code/format the same. On my drupal7 REST server 'definitions' it lists the endpoint as /rest/user/login and parameters as 'username' and 'password' strings as I've used.

我真的很感谢任何提示和帮助吗?

I'd really appreciate any tips and help?

调用REQUEST时出错 错误域= NSCocoaErrorDomain代码= 3840字符1周围的值无效." UserInfo = {NSDebugDescription =字符1周围的值无效.}

error calling REQUEST Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1." UserInfo={NSDebugDescription=Invalid value around character 1.}

这是我的代码

@IBAction func loginButtonTapped(sender: AnyObject) { //using Alamofire let dataEndpoint: String = "www.example/rest/user/login" let newData = ["username":"Mickey", "password":"123"] Alamofire.request(.POST, dataEndpoint, parameters: newData, encoding: .JSON) .responseJSON { response in guard response.result.error == nil else { // got an error in posting the data, need to handle it print("error calling REQUEST") print(response.result.error!) return } guard let value = response.result.value else { print("no result data when calling request") return } let data = JSON(value) print("The result is: " + data.description) } }

谢谢

推荐答案

在URL端点的末尾添加.json已解决了该错误.即 www.example/rest/user/login.json

Adding .json at the end of the URL endpoint has solved the error. ie www.example/rest/user/login.json

更多推荐

快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值".

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

发布评论

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

>www.elefans.com

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