Check if NSDictionary is empty

后端 未结 8 1376
感情败类
感情败类 2021-02-13 02:22

I want to check if an NSDictionary is empty. I am doing it like this.

  mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@\"dicV         


        
8条回答
  •  滥情空心
    2021-02-13 03:18

    I had a bit different issue but it is related so i would like to share it here.

    I was fetching the webservices & storing data in NSDictionary & again Fetching objectForKey which was Null. So the solution i found is as under

    NSMutableDictionary *result = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
    
        // NSLog(@"%@" , result);
    
        NSMutableDictionary *sup = [result objectForKey:@"keysupplied"];
        NSNull *n=[NSNull null];
        if ( sup ! = n ){
          //Your code if its not null
        }
    

    The reason behind using NSNull was it was returning (NSNull *) when i debugged the application So i finally figured out this way.

提交回复
热议问题