解析[Xcode Swift]时出现“由于数据格式不正确而无法读取”

时间:2019-10-15 01:16:40

标签: swift xcode parsing heroku error-handling

我使用heroku进行了简单的登录,但是我遇到了常见错误

the data couldn't be read because it isn't in the correct format

我的输入均不为空,请参见以下打印输出:

输入:

User field = "testuser"

password field = "1"

email field = "testemail@gmail.com"

fullname field = "me tester"

这是我的代码:

@IBAction func signUpBtn_click(_ sender: AnyObject) {
    print("sign up pressed")

    let user = PFUser()
    user.username = usernameTxt.text?.lowercased()
    user.email = emailTxt.text?.lowercased()
    user.password = passwordTxt.text
    user["fullname"] = fullnameTxt.text?.lowercased()
    print("user-->", user)

    user.signUpInBackground { (success, error) -> Void in
        if success {
            print("Logged in")

            UserDefaults.standard.set(user.username, forKey: "username")
            UserDefaults.standard.synchronize()   



            let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
            appDelegate.login()

        } else {

            let alert = UIAlertController(title: "Error", message: error!.localizedDescription, preferredStyle: UIAlertController.Style.alert)
            let ok = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
            alert.addAction(ok)
            self.present(alert, animated: true, completion: nil)
        }
    }
}

打印出=

user--> <PFUser: 0x600002225000, objectId: new, localId: (null)> {
email = "testemail@gmail.com";
fullname = "me tester";
password = 1;
username = testuser;
}

有人可以帮助解决这个问题吗?

谢谢

0 个答案:

没有答案