0

Here I am getting the Notification List null and it is causing me an exception. Here is my code:

if([[response.data valueForKey:@"NotificationList"] isEqual:@""] || [[response.data valueForKey:@"NotificationList"] isEqual:@"<null>"]) {

  NSLog(@"Data not available.!!!");

}
else
{
  NSLog(@"Data available.!!!");
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Pankaj Chahakar
  • 25
  • 2
  • 11

2 Answers2

2

When an object is printed or logged as "<null>", that does not mean it's a string object whose contents are <, n, u, l, l, and >. (Well, it doesn't usually mean that.)

Rather, "<null>" is how the singleton instance of NSNull describes itself.

So, the proper test is:

id notificationList = [response.data valueForKey:@"NotificationList"];
if (!notificationList || [notificationList isKindOfClass:[NSNull class]])
    NSLog(@"Data not available.!!!");
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
0

You should just be able to check for the key returning a value...

if(!response.data[@"NotificationList"]) {

  NSLog(@"Data not available.!!!");

}
else
{
    NSLog(@"Data available.!!!");
}

https://stackoverflow.com/a/2784675/285190 - for more details

Flexicoder
  • 8,251
  • 4
  • 42
  • 56