视频列表下载(采用JSON)
2016-08-08 00:00
141 查看
摘要: 视频列表下载(采用JSON)
####2.1.从网上加载资源
####3.1.tableView
####github
github
JSON解析
#####1.1.JSON解析-(void) parseJSON{ //URL NSURL *url=[NSURL URLWithString:@"http://120.25.226.186:32812/video"]; //新建一个请求对象 NSURLRequest *request=[NSURLRequest requestWithURL:url]; // [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { //NSJSONReadingMutableContainers //NSJSONReadingMutableLeaves //NSJSONReadingAllowFragments NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; [dic writeToFile:@"/Users/hyl/Desktop/video.plist" atomically:YES]; }]; }
####2.1.从网上加载资源
-(void) parseJSon2{ //URL NSURL *url=[NSURL URLWithString:@"http://120.25.226.186:32812/video"]; //新建一个请求对象 NSURLRequest *request=[NSURLRequest requestWithURL:url]; NSURLSession *session=[NSURLSession sharedSession]; // [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { // self.videoDic=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; // }]; NSURLSessionDataTask *dataTask=[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { self.videoDic=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil][@"videos"]; // NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]); //NSLog(@"%@",self.videoDic[@"videos"]); [self.tableView reloadData]; }]; [dataTask resume]; }
####3.1.tableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.videoArr.count; } -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"video"]; HYLVideo *video=self.videoArr[indexPath.row]; NSString *imageURL=[@"http://120.25.226.186:32812" stringByAppendingPathComponent:video.image]; [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageURL]]; // cell.imageView.image=[UIImage imageNamed:video.image]; cell.detailTextLabel.text=[NSString stringWithFormat:@"时长:%zd",video.length]; cell.textLabel.text=video.name; return cell; } #pragma mark - UITableViewDelete -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ HYLVideo *video=self.videoArr[indexPath.row]; NSString *videoURL=[@"http://120.25.226.186:32812" stringByAppendingPathComponent:video.url]; MPMoviePlayerViewController *vc=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:videoURL]]; [self presentViewController:vc animated:YES completion:nil]; }
####github
github
相关文章推荐
- Win8开发从入门到项目 - 视频下载列表
- 封装的工具类(网络获取Json,图片,下载图片,下载Mp3,下载视频)
- Android 从web应用获取json格式的视频资讯并列表显示在屏幕上
- AS2.0列表带图片视频播放器【附原码下载】
- YT列表视频下载
- android 从服务器端下载图片列表 服务器端封装json
- Retrofit+RXJava_多线程下载视频列表
- IE8下struts2 采用ajax提交表单,返回json字符串,解析不了,直接保存json字符串。提示下载action.
- WPF下采用C#实现FTP上传下载获取文件列表
- 推荐:走遍美国视频下载
- 蛙蛙推荐:微软网络讲座系列教程视频下载(2004年1月到2005年4越)
- Mambo视频教程下载(安装、模板、组件、模块、触发器)
- 采用HttpServlet 实现web文件下载
- MSDN WebCast网络广播全部下载列表
- 列车时刻表查询器0.6版(SmartPhone版)发布,采用了SQLite数据引擎,欢迎下载试用。
- [12/22更新]Exchange /Windows Server视频录像下载汇总-强烈推荐
- [8/4更新]Exchange -Windows Server视频录像下载
- Microsoft TechNet视频大全!!(全部免费下载哦~~)
- 针式电子书下载列表(暂时)