First of all, "<null>"
is not a valid JSON null value.
Written it that way, it is simply a string containing the word <null>
In JSON, null is written in this way.
{ "value": null }
So, if you can't update your web service to return valid json, I suggest you to do a replace on the JSON string in the first instance.
Then when you have valid JSON null values, simply handle it with NSJSONSerialization
NSString *json = @"{ \"value\": null }";
NSError *error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error];
NSLog(@"%@", jsonObject);
This prints
2014-07-16 10:31:36.737 MacUtilities[30760:303] {
value = "<null>";
}
And debugging the class of value
po [[jsonObject objectForKey:@"value"] class];
NSNull
This because NSJSONSerialization
handles null correctly, turning it into an NSNull
instance