user2569812 user2569812 - 3 months ago 18
Objective-C Question

Objective-c: How to recieve thumbnails from a GDATA Url?

Firstly I have this gdata url which fetched a gdata feed:

This is the code to fetch the information from the url:

NSURL *feedURL = [NSURL URLWithString:@""];

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
url I only receive a
response so my question is how to fix this.


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