What do JSONSerialization options do and how do they change jsonResult?

前端 未结 3 605
遇见更好的自我
遇见更好的自我 2020-12-05 04:35

I am using JSONSerialization quite often in my project. Here is an example of my JSONSerialization code:

let json = try JSONSeriali         


        
3条回答
  •  臣服心动
    2020-12-05 05:19

    Options: [] is an empty array returns nothing.

    Whereas Options: [] can also be amend with:

    • NSJSONWritingOptions: for writing JSON data like.

      • NSJSONWritingOptions.NSJSONWritingPrettyPrinted: Specifies that the JSON data should be generated with whitespace designed to make the output more readable. If this option is not set, the most compact possible JSON representation is generated.
    • NSJSONReadingOptions: used when creating Foundation objects from JSON data.

      • NSJSONReadingOptions.MutableContainers: Specifies that arrays and dictionaries are created as mutable objects.
      • .mutableLeaves: Specifies that leaf strings in the JSON object graph are created as instances of NSMutableString.
      • .allowFragments: Specifies that the parser should allow top-level objects that are not an instance of NSArray or NSDictionary.

提交回复
热议问题