1

I want to check result of json is null or not ..I used this code

- (NSString *)likesCount {
    if ([facebook valueForKey:@"likes"] == [NSNull null]) {

        return @"";
    }
    else {

    return [facebook valueForKey:@"likes"];

    }
}

likes = 1; if it exists and if it is null "like" is not visible in output.. But if it is not present then it is returning (null) .. I used above code but it is not working.

I am printing this value of likes in UItableviewcell

UILabel *commentLike = [[UILabel alloc] initWithFrame:CGRectMake(200, 70, 100, 20)];
commentLike.font = [UIFont fontWithName:@"Arial" size:10.0];

NSString *commentLikeString = [NSString stringWithFormat:@"%@ ",[(Facebook *)[tableArray objectAtIndex:indexPath.row]likesCount]];
    commentLike.text = [NSString stringWithFormat:@"%@ Person"];
    [cell.contentView addSubview:commentLike];

Thanks

razlebe
  • 7,134
  • 6
  • 42
  • 57
DeviPhone26
  • 615
  • 2
  • 10
  • 16

2 Answers2

0

Try this code

- (NSString *)likesCount {
    if ([[facebook valueForKey:@"likes"] isEqualToString:@"(null)"] || [facebook valueForKey:@"likes"] == nil) {

        return @"";
    }
    else {

    return [facebook valueForKey:@"likes"];

    }
}
Chetan Bhalara
  • 10,326
  • 6
  • 32
  • 51
0

Use this category on NSDictionary, code will be much cleaner:

TouchJSON, dealing with NSNull

Community
  • 1
  • 1
Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92