/**
* JSON文件中的[]表示是一个数组
序列化将NSObject转换成序列数据,以便可以通过互联网进行传输
反序列化将网络上获取的数据,反向生成我们需要的对象
如果开发网络应用,可以将反序列化出来的对象保存至沙箱,以便后续开发使用
NSArray *docs =
*/
- (void)handlerJSONData:(NSData *)data{
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingOptions error:nil];
//yes展开波浪号
NSArray *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES)];
NSString *path = [docs[0]stringByAppendingString:@"json.plist"];
[array writeToFile:pathatomically:YES];
//给数组列表赋值
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary * dictin array) {
Video * video = [[Video alloc]init];
//给video赋值
[video setvalueForKeysWithDictionary:dict];
[arrayM addObject:video];
}
//这是全局的一个变量存数据的
self.dataList = arrayM;
}
//为了便于开发中的调试
- (NSString *)description{
return [NSStringstringWithFormat:@"<Video :%p Video id :%d"
"name : %@"
"teacher :%@>",self.class]
}
//为了显示中文需要写个分类
- (NSString *)descriptionWithLocale:(id)locale{
NSMutableString *str = [NSMutableStringstring];
[str appendFormat:@"%d (",self.count];
for (NSObject *objin self) {
[str appendFormat:@"\t%@\n,",obj];
}
[str appendString:@")"];
return str;
//加载图片
//1.同步加载图片
//注意,在开发网络应用时,不要使用同步方法加载图片,否则会严重影响用户体验
NSString *imagePath = [NSString stringWithFormat:@"%@%@",kBaseURL,v.imageURL];
NSURl *imageUrl = [NSURL URLWithString:imagePath];
//同步方法意味着这一指令执行完成之前,后续的指令都无法执行
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImageimageWithData:imageData];
//2.异步加载网络网络连接本身就有异步命令
}
#pragma mark 异步加载图片
//由于UITableViewCell是可重用的,为了避免用户频繁快速刷新表格,造成数据冲突,不能直接将
//UIImageView传入异步方法,
//正确解决方法是:将表格行的indexpath传入异步方法,加载完成图像后,直接刷新指定的行