从服务器获取到字典类型数据,用NSUserDefaults缓存到本地
初始的- (void)dataLoad {
NSMutableDictionary * aaa = [originalData valueForKey:@"userInfo"];
[userDefaults setValue:aaa forKey:@"data"];
[userDefaults synchronize];
}
由于数据中有CFNULL 调用下面方法,进行替换
- (void)cleanDictionary:(NSMutableDictionary *)dictionary {
[dictionary enumerateKeysAndObjectsUsingBlock:^( id key, id obj, BOOL *stop){
if(obj == [NSNull null]) {
[dictionary setObject:@"" forKey:key];
} else if ([obj isKindOfClass:[NSDictionary class]]) {
[self cleanDictionary:obj];
}
NSLog(@"key:%@,,value:%@",key,obj);
}];
}//属性列表中不能存有CFNULL,遍历进行替换
然而接收的数据无法进行数据的修改,我们就需要MutableCopy来解决
修改的- (void)dataLoad {
NSMutableDictionary * aaa = [[originalData valueForKey:@"userInfo"] mutableCopy];
[self cleanDictionary:aaa];
[userDefaults setValue:aaa forKey:@"data"];
[userDefaults synchronize];
}
这样就好了
目前还是个新手,对于mutableCopy和copy还不是很了解