NSJSONSerialization - What is the proper value to specify no NSJSONWritingOptions for dataWithJSONObject:options:error:?

StackOverflow https://stackoverflow.com/questions/19149869

Question

Apple's documentation has the NSJSONWritingOptions enum with one constant defined: NSJSONWritingPrettyPrinted, and says that "If this option is not set, the most compact possible JSON representation is generated."

I definitely want the most compact JSON representation.

My question is: what is the proper value to pass the dataWithJSONObject:options:error: function if I don't want pretty printed, and why?

The NSJSONWritingOptions enum is defined as

enum {     NSJSONWritingPrettyPrinted = (1UL << 0) }; typedef NSUInteger NSJSONWritingOptions;

I have read in a different post that 0 should be passed, but with no further explanation as to why it shouldn't be nil.

Was it helpful?

Solution

It can't be nil because it's an NSUInteger. So, you should pass 0, which represents that the option is not set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top