Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSJSONSerialization with NO Options

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.

like image 442
Fogmeister Avatar asked Jul 23 '13 16:07

Fogmeister


2 Answers

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];
like image 174
Marcus Adams Avatar answered Sep 28 '22 01:09

Marcus Adams


Options 0 is fine, that's what I use in Xcode anyway. It does not complain.

like image 41
jsd Avatar answered Sep 28 '22 02:09

jsd