Cha*_*gUZ 3 iphone plist nskeyedarchiver nsdata ios
我测试了这段代码,但它导致了SIGABRT错误.
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data]
Run Code Online (Sandbox Code Playgroud)
NSData是xml格式的plist数据.这段代码工作正常.
[urlData writeToFile:[self docPath] atomically:YES];
array = [[NSMutableArray alloc] initWithContentsOfFile:[self docPath]];
Run Code Online (Sandbox Code Playgroud)
如何在没有文件转换的情况下将NSData更改为NSArray?
这假设您已填充NSString *filepath了已保存数据文件的文件路径.
NSPropertyListFormat format;
NSData *dataFromFile = [NSData dataWithContentsOfFile:fileNameWithPath];
NSArray *arrayFromFile = nil;
if (dataFromFile) {
arrayFromFile = [NSPropertyListSerialization propertyListFromData:dataFromFile
mutabilityOption:NSPropertyListMutableContainers
format:&format
errorDescription:NULL];
}
Run Code Online (Sandbox Code Playgroud)
希望有帮助......
| 归档时间: |
|
| 查看次数: |
5959 次 |
| 最近记录: |