快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值". [英] swift error "Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 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 = "https://www.example.com/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已解决了该错误.即 https://www.example.com/rest/user/login.json
Adding .json at the end of the URL endpoint has solved the error. ie https://www.example.com/rest/user/login.json
这篇关于快速错误"Domain = NSCocoaErrorDomain Code = 3840"“字符1周围的无效值".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!