There are a few possible solutions.
1) Testing for NSNull
If you just want to test for null (I'm assuming NSNull) then the following works:
How can I check If I got null from json?
2) Replacing NSNulls with strings
If you're using a dictionary and you just want to replace all nulls with empty strings then this could be what you're looking for:
Replace all NSNull objects in an NSDictionary
3) NSDictionary category
I personally use a category which adds a new method to NSDictionary. It just returns nil if the value is NSNull (originally from TouchJSON, dealing with NSNull)
NSDictionary+Utility.h
#import <Foundation/Foundation.h>
@interface NSDictionary (Utility)
- (id)objectForKeyNotNull:(id)key;
@end
NSDictionary+Utility.m
#import "NSDictionary+Utility.h"
@implementation NSDictionary (Utility)
- (id)objectForKeyNotNull:(id)key {
id object = [self objectForKey:key];
if (object == [NSNull null]){
return nil;
}
return object;
}
@end
Implementation Class (.m)
#import "NSDictionary+Utility.h"
...
id success = [JSON objectForKeyNotNull:@"success"];
if (success == nil){
/* "success" either NSNull or didn't exist in JSON. */
}