从Reddit .JSON Parse获取布尔值

时间:2013-06-12 22:11:12

标签: ios objective-c json cocoa-touch reddit

可以查看该文件here。我正在解析属性“喜欢”,但即使我喜欢这个帖子,我也会得到<null>。我100%确定我的modhash是有效的,当我查看该文件时,我可以看到真实出现在我投票的帖子中。

我的代码:

NSData *responseData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://reddit.com/.json"]];

NSDictionary *json = [NSJSONSerialization
                      JSONObjectWithData:responseData

                      options:kNilOptions
                      error:&error];

NSArray *objects = [[json objectForKey:@"data"] objectForKey:@"children"];



postArr = [[NSMutableArray alloc] init];

int likesCnt = 0;
for (NSDictionary *object in objects) {
    NSObject *likeObj = [[object objectForKey:@"data"] objectForKey:@"likes"] ;
    NSObject *data = [object objectForKey:@"data"];  

    int voteDirection = 0;
    if(![likeObj isKindOfClass:[NSNull class]] && [[data valueForKey:@"likes"] boolValue])
        voteDirection = 1;
    else if(![likeObj isKindOfClass:[NSNull class]] && ![[data valueForKey:@"likes"] boolValue])
        voteDirection = -1;


    //Reddit Post in an NSObject Class for organizing info for specific posts.
    RedditPost *post = postArr[likesCnt];
    post.currentVote = voteDirection;
    postArr[likesCnt] = post;
    NSLog(@"Title:(%@) Vote:(%d)",post.title,voteDirection);
    likesCnt++;
}

新文件:http://www1.datafilehost.com/d/25dae11d

0 个答案:

没有答案