07-19-2023, 01:00 AM
I am using `JSONSerialization` quite often in my project.
Here is an example of my `JSONSerialization` code:
let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any]
**Note**: Options are missing for purpose and I normally have them in my project.
My problem is that I am not pretty sure what do these `options: []` do?
**What I have found about options:**
**NSJSONReadingMutableContainers:**
> Specifies that arrays and dictionaries are created as mutable objects.
**NSJSONReadingMutableLeaves:**
> Specifies that leaf strings in the JSON object graph are created as
> instances of NSMutableString.
**NSJSONReadingAllowFragments:**
> Specifies that the parser should allow top-level objects that are not
> an instance of NSArray or NSDictionary.
**Note2**: I found those definitions on :
**My question is**:
Can someone please explain me differences between those options , what should I use them for and if you could show me some code example of those options it would be perfect :).
Any help appreciated.
Thanks.
Here is an example of my `JSONSerialization` code:
let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any]
**Note**: Options are missing for purpose and I normally have them in my project.
My problem is that I am not pretty sure what do these `options: []` do?
**What I have found about options:**
**NSJSONReadingMutableContainers:**
> Specifies that arrays and dictionaries are created as mutable objects.
**NSJSONReadingMutableLeaves:**
> Specifies that leaf strings in the JSON object graph are created as
> instances of NSMutableString.
**NSJSONReadingAllowFragments:**
> Specifies that the parser should allow top-level objects that are not
> an instance of NSArray or NSDictionary.
**Note2**: I found those definitions on :
[To see links please register here]
**My question is**:
Can someone please explain me differences between those options , what should I use them for and if you could show me some code example of those options it would be perfect :).
Any help appreciated.
Thanks.