首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSON中的YouTube视频源到表视图中

JSON中的YouTube视频源到表视图中
EN

Stack Overflow用户
提问于 2012-08-05 16:15:57
回答 1查看 3K关注 0票数 0

如何将youtube上的视频转换为JSON格式,并在UITableView中列出。我需要在一次20饲料被列出,并在显示更多的按钮,然后下20个结果需要显示。

我期待确切的网址,以获得在这两种情况下的饲料。

现在我正在尝试Url,我给出了一个例子。

代码语言:javascript
复制
http://gdata.youtube.com/feeds/api/videos?start-index=11&max-results=20&v=2&alt=jsonc
http://gdata.youtube.com/feeds/api/videos?start-index=2&max-results=20&v=2&alt=jsonc

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-05 16:38:34

下面的代码解析YouTube JSON to table视图。

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    if (indexPath.row < [[_JSON valueForKeyPath:@"data.items.title"] count]) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
        cell.textLabel.text = 
        [[_JSON valueForKeyPath:@"data.items.title"] objectAtIndex:indexPath.row];
        cell.detailTextLabel.text =
        [[_JSON valueForKeyPath:@"data.items.description"] objectAtIndex:indexPath.row];
    }
    return cell;
}

获取JSON的代码如下:

代码语言:javascript
复制
- (IBAction)refresh:(id)sender {
    NSURL *url = [NSURL URLWithString:kStrJsonURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id getJSON) {
        _JSON = getJSON;
        NSLog(@"%@", _JSON);
        [self.tableView reloadData];
    } failure:nil];
    [operation start];        
}

您应该阅读关于AFNetworking的入门指南:

https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking

您可以从GitHub下载示例项目并运行它:

https://github.com/weed/p120805_YouTubeJsonParse

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11814930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档