用户默认值尝试设置非 属性 列表对象

User Defaults Attempt to set a non-property-list object

我在将具有 39 个参数(键和值)的 NSDictionary 对象存储到 UserDefault 对象时遇到了问题。代码在我留下评论的地方崩溃了。 self.userDefaults.set(数据, forKey: "userData")

这是我遇到的错误:

[User Defaults] Attempt to set a non-property-list object {
city = "";
country = "";
cover = "default.png";
date = "2019-10-02";
description = "";
email = "hashdoge@outlook.com";
"email_comment" = 0;
"email_like" = 0;
"email_new_friend" = 0;
"email_newsletter" = 1;
facebook = "";
"first_name" = "";
follower = 3;
following = 2;
gender = 0;
gplus = "";
idu = 42;
image = "default.png";
ip = "";
"last_name" = "";
lastfm = "";
likes = 3;
"login_token" = "<null>";
"logout_time" = 0;
myspace = "";
notificationc = 1;
notificationd = 1;
notificationf = 1;
notificationl = 1;
offline = 0;
online = 1570879800;
password = "y7675ze1wZ/riJgQ2e";
private = 0;
salted = "y$GKUmSJGcq932DMJGMA8791RIO";
soundcloud = "";
suspended = 0;
totaltracks = 0;
tumblr = "";
twitter = "";
username = HashDoge;
vimeo = "";
website = "";
youtube = "";} as an NSUserDefaults/CFPreferences value for key userData

这是我正在尝试使用的代码 代码:

func callApigetLoginResponse(){
    FTIndicator.showProgressWithmessage("", userInteractionEnable: false)
    let parameters = ["useremail":txtEmail.text!,"password":txtPassword.text!]
    SignInGet.ApiGetSignIn(parameters: parameters as NSDictionary) { (Result, Error) in
       // print(Result!)
        if Error != nil{
            print(Error!)
        }else{
            let dataDict:NSDictionary = Result as! NSDictionary
            if (dataDict["success"]as! Int == 1){
               let  loginResponse = dataDict["userlogin"] as! NSArray
                let data = loginResponse[0] as! NSDictionary
                let uid = data["idu"] as! String
                self.sendTokenaApi(uid: uid)
                self.userDefaults.set(uid, forKey: "id")
                self.userDefaults.set(data, forKey: "userData") // code crashes here
                self.userDefaults.synchronize()
                let updateUserInfo = UpdateUserInfoUtl()
                updateUserInfo.callApigetUserDataResponse()
                self.pushToHomeController()
            }else if (dataDict["success"]as! Int == 0) {
             let  message = dataDict["userlogin"] as! String
                FTIndicator.showInfo(withMessage: message)
            }
            }
        }
    }

我修好了。问题是 login_token 中的“< n u l l >”。 我在数据库中将它作为一个空字符串 "" 并且它起作用了。