I have an app making a request to a JSON on a server to fetch some data . All works fine until
the value for a field in the JSON has the null value . Then the app crashes .
So I get the data , put it in a NSDictionary , and then access all the values in that dictionary . I’ve tried with those if() statements but still , if the value is null , the app crashes .
if([item valueForKey:@"title"]!=NULL)
[sbcvItem setTitle:[item valueForKey:@"title"]];
if([item valueForKey:@"desc"]!=NULL)
[sbcvItem setDesc:[item valueForKey:@"desc"]];
if([item valueForKey:@"url"]!=NULL)
[sbcvItem setUrl:[item valueForKey:@"url"]];
Any suggestion is welcome .
Neither
NSDictionarynorNSArraycan storenil(orNULL) as a value. Instead, we use a placeholder object. That placeholder object is a singleton of classNSNull, and you get a pointer to it using[NSNull null]. So you need to test like this: