Reputation: 160
Firstly I have this gdata url which fetched a gdata feed:
https://gdata.youtube.com/feeds/api/videos/tge2BfiIXiE?v=2&alt=jsonc
This is the code to fetch the information from the url:
NSURL *feedURL = [NSURL URLWithString:@"https://gdata.youtube.com/feeds/api/videos/tge2BfiIXiE?v=2&alt=jsonc"];
NSData *jsonData = [NSData dataWithContentsOfURL:feedURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSDictionary *data1 = [dataDictionary objectForKey:@"data"];
NSString *t = [data1 objectForKey:@"title"];
NSLog(@"Title:%@", t);
NSDictionary *thumbs = [dataDictionary objectForKey:@"thumbnail"];
NSURL *standardThumb = [thumbs objectForKey:@"sqDefault"];
NSURL *hdThumb = [thumbs objectForKey:@"hqDefault"];
The code above fetches the title of the video. However the code does not successfully fetch the thumbnails from the gdata url. And when I attempt to NSLOG
the hdThumb
url I only receive a null
response so my question is how to fix this.
Upvotes: 1
Views: 203
Reputation: 1297
Try this:
NSDictionary *thumbs = [[dataDictionary objectForKey:@"data"] objectForKey:@"thumbnail"];
Or you can use this syntax to access dictionary values:
NSDictionary *thumbs = dataDictionary[@"data"][@"thumbnail"];
your problem was that you just forgot to access the "data" dictionary first
Upvotes: 1