How to check value is coming from json is null or not?

后端 未结 2 1069
遇见更好的自我
遇见更好的自我 2021-01-27 03:18

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

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

               


        
相关标签:
2条回答
  • 2021-01-27 04:11

    Try this code

    - (NSString *)likesCount {
        if ([[facebook valueForKey:@"likes"] isEqualToString:@"(null)"] || [facebook valueForKey:@"likes"] == nil) {
    
            return @"";
        }
        else {
    
        return [facebook valueForKey:@"likes"];
    
        }
    }
    
    0 讨论(0)
  • 2021-01-27 04:12

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

    TouchJSON, dealing with NSNull

    0 讨论(0)
提交回复
热议问题