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

问题描述 投票:0回答:1

我将具有39个参数(键和值)的NSDictionary对象存储到UserDefault对象中时遇到问题。代码在我留下评论的位置崩溃。 self.userDefaults.set(data,forKey:“ userData”)

这是我得到的错误:

[User Defaults] Attempt to set a non-property-list object {
city = "";
country = "";
cover = "default.png";
date = "2019-10-02";
description = "";
email = "[email protected]";
"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 = "$2y$107675ze1wZ/riJgQ2e";
private = 0;
salted = "$2y$10$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)
            }
            }
        }
    }
swift xcode nsdictionary userdefaults
1个回答
0
投票

我修复了它。问题是login_token中的“ ”。我在数据库中将其作为空字符串“”进行了工作。

© www.soinside.com 2019 - 2024. All rights reserved.