iOS - NSJSONReadingOptions与NSJSONWritingOptions

图片源于网络

NSJSONReadingOptions

typedef NS_OPTIONS(NSUInteger, NSJSONReadingOptions) {
    NSJSONReadingMutableContainers = (1UL << 0),
    NSJSONReadingMutableLeaves = (1UL << 1),
    NSJSONReadingAllowFragments = (1UL << 2)
} API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0));
  • NSJSONReadingMutableContainers = (1UL << 0), // 返回可变容器,NSMutableDictionary或NSMutableArray

  • NSJSONReadingMutableLeaves = (1UL << 1), // 不仅返回的最外层是可变的, 内部的子数值或字典也是可变对象

  • NSJSONReadingAllowFragments = (1UL << 2) // 返回允许JSON字符串最外层既不是NSArray也不是NSDictionary,但必须是有效的JSON Fragment.可以是如 "10"

NSJSONWritingOptions

typedef NS_OPTIONS(NSUInteger, NSJSONWritingOptions) {
    NSJSONWritingPrettyPrinted = (1UL << 0),

    /* Sorts dictionary keys for output using [NSLocale systemLocale]. Keys are compared using NSNumericSearch. The specific sorting method used is subject to change.
     */
    NSJSONWritingSortedKeys API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0)) = (1UL << 1)
} API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0));

  • NSJSONWritingPrettyPrinted = (1UL << 0) //是将生成的json数据格式化输出,这样可读性高,不设置则输出的json字符串就是一整行。

  • NSJSONWritingSortedKeys //输出的json字符串就是一整行

参考

IOS 系统API---NSJSONSerialization四个枚举什么意思

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容