iOS - NSJSONReadingOptions与NSJSONWritingOptions

iOS - NSJSONReadingOptions与NSJSONWritingOptions_第1张图片
图片源于网络

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四个枚举什么意思

你可能感兴趣的:(iOS - NSJSONReadingOptions与NSJSONWritingOptions)