使用NSDate()作为Parse.com的密钥保存Dicitionary失败

时间:2016-03-06 15:38:04

标签: swift parse-platform

我正在尝试将[NSDate: Double]类型的字典保存到PFUser.currentUser's记录中:

let user = PFUser.currentUser()!
let date = NSDate()
user["savedDictionary"] = [date: 1.0] // error, see below. ["test": 1.0] works though

user.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
    if error == nil {
        print("Dictionary uploaded!")
    } else {
       print(error)
    }
}

我得到的错误:

Caught "NSInvalidArgumentException" with reason "Invalid (non-string) key in JSON dictionary":

此错误还会导致PFUser.currentUser注销。

1 个答案:

答案 0 :(得分:1)

将日期键转换为字符串:

Here is my code:
var firstPart;
var secondPart;
var str = "hello123"
alert(str.split(""));