0

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

我的代码:

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

4

0 回答 0