iOS NSUserDefaults数据保存报错:Attempt to set a non-property-list object...

//联系人:石虎QQ: 1224614774昵称:嗡嘛呢叭咪哄

在使用NSUserDefaults的时候插入数据有时候会报以下错误:

Attempt to set a non-property-list object {type = immutable dict, count = 27,

entries =>

3 : ext_attr = {contents = ""}

4 : zhicheng = {contents = ""}

5 : code = {contents = "YS1000000000011"}

6 : zhuzhi = {contents = ""}

10 : sex = {contents = ""}

14 : cat_id = {contents = ""}

15 : pass = 123123

16 : keshi =

18 : name = {contents = "新医生"}

19 : sp = {contents = ""}

20 : moreinfo = {contents = ""}

21 : state = {contents = ""}

22 : {contents = "comment_num"} = 0

23 : id = 11

25 : p_attr = {contents = ""}

26 : pcolumn = 1

27 : pic = {contents = "http://58.61.37.228:3080/td_yisheng/static/img/photo.gif"}

28 : {contents = "zhizhaopic"} = {contents = ""}

29 : mobile = {contents = "18682355562"}

30 : showtpl = 1

31 : email = {contents = ""}

32 : area = {contents = "区域"}

33 : uptime = {type = immutable, count = 1, values = (

0 : {contents = ""}

)}

36 : price = {type = immutable dict, count = 5,

entries =>

2 : baoyue = 1

3 : dianhua = 1

4 : huizhen = 1

5 : yuyue = 1

6 : zixun = 1

}

38 : {contents = "comment_rank"} = 5

39 : regtime = {contents = "1442394762"}

40 : patchcode = {contents = ""}

}

as an NSUserDefaults/CFPreferences value for key UserModelDic

这种错误的原因是插入了不识别的数据类型,NSUserDefaults支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型。

自定义的类型需要转成NSData再存入。

===============================================

我原来认为NSUserDefaults存不了数组,又换成了字典,但是还是报错,最后求助网友大神解决了,是我里边的数据结构有"",而NSUserDefaults是不能被成功解析并存入的,所有在存入之前需要将里边的""改成""即可。

谢谢!!!

你可能感兴趣的:(iOS NSUserDefaults数据保存报错:Attempt to set a non-property-list object...)