//归档: 就是把数据按照定义的格式存储到文件中,方便从文件恢复对象数据
//解归档: 从归档文件中读取数据到对象变量中
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//归档
/*NSData *data = [NSKeyedArchiver archivedDataWithRootObject:@"helloworld"];
BOOL ret = [data writeToFile:@"/Users/zhangxueming/Desktop/zhang.plist" atomically:YES];
if (ret) {
NSLog(@"文件归档成功");
}
else
{
NSLog(@"文件归档失败");
}*/
#if 0
NSArray *arr= @[@"qian",@"feng",@"hello",@"world"];
BOOL ret1 = [NSKeyedArchiver archiveRootObject:arr toFile:@"/Users/zhangxueming/Desktop/abc.plist"];
if (ret1) {
NSLog(@"文件归档成功");
}
else
{
NSLog(@"文件归档失败");
}
#else
//解归档
//[NSKeyedUnarchiver unarchiveObjectWithData:]
// NSKeyedUnarchiver *obj=[NSKeyedUnarchiver unarchiveObjectWithFile:@"/Users/zhangxueming/Desktop/abc.plist"];
// NSLog(@"%@", obj);
NSData *data1 = [NSData dataWithContentsOfFile:@"/Users/zhangxueming/Desktop/abc.plist"];
NSKeyedUnarchiver *obj1 = [NSKeyedUnarchiver unarchiveObjectWithData:data1];
NSLog(@"%@", obj1);
#endif
}
return 0;
}
//从本地json文件中解析数据
#import <Foundation/Foundation.h>
//json解析
//json语法: @[@"One", @"Two"] @{@"key":@"value",@"key2":@"value2"}
//类似于