-2

I have a question about KNilOptions and NSJSONReadingMutableContainers. i thank they have a same function. Because KNilOptions Equal to Zero and NSJSONReadingMutableContainers too.

is it right?

NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

// NSJSONReadingMutableContainers is equal to kNilOptions

sixleaves
  • 9
  • 2

2 Answers2

2

Here's the definition of NSJSONReadingMutableContainers:

NSJSONReadingMutableContainers = (1UL << 0),

So NSJSONReadingMutableContainers is defined as 1, not 0. It does not have the same value as kNilOptions.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

First the small introduction about KNilOptions and NSJSONReadingMutableContainers. KNilOptions stand for 0 and NSJSONReadingMutableContainers is stand for (1UL << 0) in enum.

So in the C++, UL just means the literal is an unsigned long integer type. The default integer literal is int.

This both (KNilOptions and NSJSONReadingMutableContainers) will help in the options for reading the JSON data and creating the Foundation objects.

You can create the dictionary from the JSON string with the NSJSONReadingMutableContainers option, which creates all arrays and dictionaries as mutable objects so that you can add a new key in object (Dictionary) and add new Dictionary in your array without changing in the reference and you will get the full mutable structure.

Ravi B
  • 1,574
  • 2
  • 14
  • 31