1、NSUserDefaults 数据保存报错。
** Attempt to set a non-property-list object <CFBasicHash 0x7f9ac2cd9df0 [0x10430f7b0]>{type = immutable dict, count = 4,**
**entries =>**
** 0 : head_pic = <CFNull 0x10430faf0 [0x10430f7b0]>**
** 3 : nickname = <CFString 0x7f9ac50b27c0 [0x10430f7b0]>{contents = "****张三****"}**
** 5 : department = <CFString 0x7f9ac2cdfdb0 [0x10430f7b0]>{contents = "****售票部****"}**
** 6 : job = <CFString 0x7f9ac2cc2ba0 [0x10430f7b0]>{contents = "****系统管理员****"}**
**}**
** as an NSUserDefaults/CFPreferences value for key user**
2、原因:插入了不识别的数据类型,NSUserDefaults支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型。自定义的类型需要转成NSData再存入。
3、解决:
而我这个错误的原因:
"user": {
"nickname": "张三",
"job": "系统管理员",
"department": "售票部",
"head_pic": null
}
是我里边的数据结构有"null",而NSUserDefaults是不能被成功解析并存入的,所有在存入之前需要将里边的"null"改成 "" 即可。