我对 SBJSON 解析器有疑问。我正在尝试从返回 json 文件的网站获取一些信息。然后我将其解析为字符串,然后解析为字典(工作正常)。但是,当我想要该字典中的最后一个元素(名称)时,它只会给我一个错误。这是我的代码:
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);
这是输出:
2012-10-10 11:11:47.731 quoteGen[13862:c07] (
{
name = {
"$t" = CommanderKrieger;
};
uri = {
"$t" = "http://gdata.youtube.com/feeds/api/users/CommanderKrieger";
};
}
)
我如何获得名称或 uri?