数据的归档与解归档

将一些轻量级的json存在本地 和取出的一些操作

+ (BOOL)archivingJsonWith:(id)json {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *Json_path= [path stringByAppendingPathComponent:@"newsJsonFile.json"];
    //==写入文件
//    NSLog(@"%@",[json writeToFile:Json_path atomically:YES] ? @"Succeed":@"Failed");
    if ([json writeToFile:Json_path atomically:YES]) {
        return YES;
    } else {
        NSLog(@"json归档失败");
        return NO;
    }
}
+ (id)readingJson{
//  读取Json
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *Json_path= [path stringByAppendingPathComponent:@"newsJsonFile.json"];
    return [NSArray arrayWithContentsOfFile:Json_path];
}

猜你喜欢

转载自blog.csdn.net/goods_boy/article/details/78215318