Search code examples
objective-ciosnsjsonserialization

Immutable NSJSONReadingOptions in NSJSONSerialization


To DeSerialize a JSON String I am using the following method:

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error

But, I found that reading option returns mutable Object. Is there a way using which I will be able receive object which is immutable?


Solution

  • You should only get mutable objects if your NSJSONReadingOptions parameter includes NSJSONReadingMutableContainers. Indeed, when I call with options of 0, I get a standard NSDictionary, but if I use NSJSONReadingMutableContainers, I get a NSMutableDictionary. What are you using for your options value?