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

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

 
 

Attempt to set a non-property-list object <CFBasicHash 0x7f9c1a5cce80 [0x11192c7b0]>{type = immutable dict, count = 27,

entries =>

3 : ext_attr = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

4 : zhicheng = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

5 : code = <CFString 0x7f9c1a54e900 [0x11192c7b0]>{contents = "YS1000000000011"}

6 : zhuzhi = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

10 : sex = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

14 : cat_id = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

15 : pass = 123123

16 : keshi = <CFNull 0x11192caf0 [0x11192c7b0]>

18 : name = <CFString 0x7f9c1a566740 [0x11192c7b0]>{contents = "新医生"}

19 : sp = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

20 : moreinfo = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

21 : state = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

22 : <CFString 0x7f9c1a564dc0 [0x11192c7b0]>{contents = "comment_num"} = 0

23 : id = 11

25 : p_attr = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

26 : pcolumn = 1

27 : pic = <CFString 0x7f9c1a56d330 [0x11192c7b0]>{contents = "http://58.61.37.228:3080/td_yisheng/static/img/photo.gif"}

28 : <CFString 0x7f9c1a5165f0 [0x11192c7b0]>{contents = "zhizhaopic"} = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

29 : mobile = <CFString 0x7f9c1c8f8ee0 [0x11192c7b0]>{contents = "18682355562"}

30 : showtpl = 1

31 : email = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

32 : area = <CFString 0x7f9c1c8f3ba0 [0x11192c7b0]>{contents = "区域"}

33 : uptime = <CFArray 0x7f9c1a5ceff0 [0x11192c7b0]>{type = immutable, count = 1, values = (

0 : <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

)}

36 : price = <CFBasicHash 0x7f9c1c8e3080 [0x11192c7b0]>{type = immutable dict, count = 5,

entries =>

2 : baoyue = 1

3 : dianhua = 1

4 : huizhen = 1

5 : yuyue = 1

6 : zixun = 1

}

38 : <CFString 0x7f9c1c8e2c60 [0x11192c7b0]>{contents = "comment_rank"} = 5

39 : regtime = <CFString 0x7f9c1c8fb2b0 [0x11192c7b0]>{contents = "1442394762"}

40 : patchcode = <CFString 0x110446380 [0x11192c7b0]>{contents = ""}

}

 as an NSUserDefaults/CFPreferences value for key UserModelDic

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

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

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

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

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