【发布时间】:2011-02-18 00:51:17
【问题描述】:
我想序列化一个数组和一个整数。当我只保存整数时,它可以工作。当我添加数组时,它失败了。
NSArray *tempArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [tempArray objectAtIndex:0];
tempArray = nil;
tempArray = [NSArray arrayWithObjects:
( (someOtherArray != nil) ? (id) someOtherArray : [NSNull null] ),
[NSNumber numberWithInt:someIntValue],
nil];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.plist", docsPath, kDataFilename];
NSString *errString;
NSData *serializedStrings= [NSPropertyListSerialization
dataFromPropertyList:tempArray
format:NSPropertyListBinaryFormat_v1_0
errorDescription:&errString];
if( errString != nil ) {
NSLog(@"SaveData NSpropertyListSerialization error: %@", [errString description]);
[errString release];
}
// returns NO
BOOL success = [serializedStrings writeToFile:filePath atomically:YES];
数组可能为零,所以我先检查一下。我还尝试了 [NSNumber numberWithInt:0] 而不是 [NSNull null] 只是想看看它是否可以代替 null 工作,但它没有。
我还得到:NSpropertyListSerialization 错误:属性列表对格式无效
【问题讨论】:
标签: iphone objective-c