NSKeyedUnarchiver initForReadingWithData:难以理解的归档崩溃

时间:2013-11-21 10:01:19

标签: ios nskeyedunarchiver

在解压缩包含xml字符串的文件时,我遇到以下问题。

它崩溃在以下一行:

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

'data'(27580字节)来自:

NSMutableData *data = [NSData dataWithContentsOfURL:url];

我遇到了崩溃:

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:' * - [NSKeyedUnarchiver   initForReadingWithData:]:难以理解的存档(0x62,0x70,0x6c,   0x69,0x73,0x74,0x30,0x30)'

文件是这样创建的:

NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

NSData *project = [ProjectToXML convertProject:SelectedProject];

[archiver encodeObject:project forKey:kProjectKey];
[archiver finishEncoding];

'convertProject:'基本上创建了一个带有xml内容的NSMutableString并将其转换为NSData('encoding'为utf-8):

[xmlString dataUsingEncoding: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)encoding)) allowLossyConversion:NO];

0 个答案:

没有答案