数据的归档与解归档

2017-10-12 19:40:01来源:CSDN作者:Goods_boy人点击

分享

将一些轻量级的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];}

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台