可以查看该文件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++;
}