解析JSON以获取Google Reader标签信息

时间:2011-01-18 08:21:45

标签: iphone objective-c json google-reader

我正在尝试制作谷歌阅读器应用程序。我能够以JSON格式获取订阅列表,如下所示:

{"subscriptions":[{"id":"feed/http://aspn.activestate.com/ASPN/Cookbook/Python/index_rss","title":"ActiveState Code: Python recipes","categories":[{"id":"user/014533032765194560dwd0/label/Programming","label":"Programming"}],"sortid":"E6312EFB","firstitemmsec":"1258141669516","htmlUrl":"http://code.activestate.com/recipes/langs/python/"},

我有兴趣将标签值(在上面的例子中为“Programming”)放入一个数组中。这是我目前的代码:

-(BOOL)parsedSuccess {
     SBJsonParser *parser = [[SBJsonParser alloc]init];
    if (!receivedData) {
        [self getSubscriptionList:GOOGLE_READER_SUBSCRIPTION_LIST];

    }
    NSMutableString *body = [[NSMutableString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];

    if (body) {
        NSArray *feeds = [parser objectWithString:body error:nil];
        NSDictionary *results = [body JSONValue];
        NSArray *subs = [results valueForKey:@"subscriptions"];
        NSString *subTitles;

        for (NSDictionary *title in subs){
            subTitles = [title objectForKey:@"categories"];
                NSLog(@"%@",subTitles);
        }

    }
    return YES;
}

有人可以帮助我获取标签值吗?

1 个答案:

答案 0 :(得分:1)

[[[[[result valueforkey:@"subscription"]objectatindex:0]valueforkey:@"categories"]objectatindex:intvalue]valueforkey:@"label"];

我只是帮助制作逻辑。在实施之前一定要检查拼写错误。