当我使用NSKeyedUnarchiver进行解码时,即使传递有效的数据对象,NSDictionary也是nil

时间:2015-08-11 04:33:24

标签: ios core-data nskeyedunarchiver

我使用NSKeyedArchiver存储NSDictionary对象,核心数据下面有以下代码。

            NSMutableData *data = [[NSMutableData alloc] init];
            NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
            [archiver encodeObject:dict forKey:@"voterExtraInfo"];
            [archiver finishEncoding];
            [voter setValue:data forKey:@"extraInfo"];

当使用键@“voterExtraInfo”检索相同的字典时,NSDictionary显示为nil。 我的检索代码是

    NSMutableData *data = [[NSMutableData alloc] initWithData:voter.extraInfo];
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    NSDictionary *extraData= [unarchiver decodeObjectForKey:@"voterExtraInfo"];
    [unarchiver finishDecoding];

请建议。这是我存储的词典。

{
     "ethnicity": "Hispanic",
     "voter_score": "45",
     "ipsum": "foo bar"
}

0 个答案:

没有答案