Take the 2-minute tour ×

I have a problem with the SBJSON Parser. I'm trying to get some information from a website which gives back a json file. Then I parse that into a string and then into a dictionary (works fine). But when I want the last element (name) from that dict it just gives me an error. Here's my code:

SBJsonParser *parser = [[SBJsonParser alloc] init];

self.videoId = videoId;
// Grab the contents from the url and save it in a string
NSString *content = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://gdata.youtube.com/feeds/api/videos/%@?alt=json",videoId]] encoding:NSUTF8StringEncoding error:nil];
// Save the information from the string in a dict
NSDictionary *dict = [parser objectWithString:content error:nil];

NSArray *string = [[dict objectForKey:@"entry"] objectForKey:@"author"];

NSLog(@"%@", string);

Here's the output:

2012-10-10 11:11:47.731 quoteGen[13862:c07] (
    name =         {
        "$t" = CommanderKrieger;
    uri =         {
        "$t" = "http://gdata.youtube.com/feeds/api/users/CommanderKrieger";


How do I get the name or uri?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted
NSString *name = [[[string objectAtIndex:0] objectForKey:@"name"] objectForKey:@"$t"];
 NSString *urlString = [[[string objectAtIndex:0] objectForKey:@"uri"] objectForKey:@"$t"];

I think it will be helpful to you.

share|improve this answer
Thanks that solved it. :) –  user1734282 Oct 10 '12 at 9:48
add comment

Your Answer


