5

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.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • 1
    A value of `0` means "no options". There is no specific enum value provided by Apple for "no options". – rmaddy Jul 23 '13 at 16:49
  • I thought that was the case but when I used it in AppCode it didn't like me not using the correct enum. I'll just live with the warning, thanks. – Fogmeister Jul 23 '13 at 16:51
  • @rmaddy There is, it's called `kNilOptions`. –  Jul 23 '13 at 18:58
  • @H2CO3 There is no such symbol in the iOS docs. Maybe it is only available under OSX. Update: Though it seems the symbol can be used in iOS without any added imports. Good to know. – rmaddy Jul 23 '13 at 18:59
  • @rmaddy I have it in `` in the iPhoneOS5.1.sdk folder. –  Jul 23 '13 at 19:10
  • @H2CO3 To clarify, `kNilOptions` is not in the iOS documentation but the symbol can be used in an iOS app. `` must be included ultimately by `Foundation.h`. – rmaddy Jul 23 '13 at 19:14

2 Answers2

15

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];
Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
2

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

jsd
  • 7,673
  • 5
  • 27
  • 47