将YouTube视频源以JSON格式导入表格视图
问题描述:
如何获取JSON格式的youtube视频列表UITableView
。我需要一次20饲料被列出,并在显示更多的按钮,然后需要显示20个结果。将YouTube视频源以JSON格式导入表格视图
我期待在这两种情况下获得feed的确切网址。
现在我正在尝试Url我举例。
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
由于提前
答
下面码分析YouTube的JSON表视图。
- (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低于:
- (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并运行它:
朋友,你能告诉我如何以简单的方式发送这个请求到服务器。你给出的例子太奇怪了。 – 2012-08-05 09:32:59
我尝试了几次使用NSURLRequest和NSURLConnection等标准函数来发出HTTP请求,但这些方法对我来说是非常痛苦的。最后,我决定使用网络库“AFNetworking”,通过它可以在几行代码中获得JSON。 – weed 2012-08-05 10:12:03
对不起朋友,我是用iphone编码的文盲。请帮助我请求AFNetworking的方式。请给我代码。 – 2012-08-05 10:43:14