I've used this in several projects...
[NSJSONSerialization dataWithJSONObject:someObject options:0 error:nil]
but I don't know how to specify no options. This is both for reading and writing.
I saw an example somewhere where the person had used a constant value instead of just 0 but I can't find it.
Is there a way to properly specify no options?
AppCode displays a warning if I use the above code.
You can use kNilOptions. Ray Wenderlich uses it in his iOS JSON tutorial, and I've used it without issues.
kNilOptions is defined in MacTypes.h:
enum {
kNilOptions = 0
};
Since NSJSONReadingOptions is an enum, kNilOptions is suitable, and as Ray Wenderlich points out in the tutorial, it's more descriptive than simply 0:
NSDictionary *dictionary = [NSJSONSerialization dataWithJSONObject:someObject
options:kNilOptions
error:nil];
Options 0 is fine, that's what I use in Xcode anyway. It does not complain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With