【问题标题】:NSPropertyListSerialization returns nil when trying to convert NSDictionary to NSDataNSPropertyListSerialization 在尝试将 NSDictionary 转换为 NSData 时返回 nil
【发布时间】:2012-03-15 08:41:51
【问题描述】:

我正在尝试将 NSDictionary 转换为 NSData 以存储在核心数据中,但我得到一个 nil 值返回给我。调用后错误状态为“未知格式选项”。

NSString *error = nil;
NSData *d = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListImmutable errorDescription:&error];

我要转换的数据是一个以 NSStrings 作为键和值的 NSDictionary。这是数据字典的转储:

Printing description of data:
<CFBasicHash 0xc96fd60 [0x18ecb38]>{type = immutable dict, count = 4,
entries =>
0 : <CFString 0x17c9fc [0x18ecb38]>{contents = "title"} = <CFString 0xecc8040 [0x18ecb38]>{contents = "test"}
1 : <CFString 0x17ca2c [0x18ecb38]>{contents = "author"} = <CFString 0xc9643f0 [0x18ecb38]>{contents = "test"}
2 : <CFString 0x17ca0c [0x18ecb38]>{contents = "goal"} = <CFString 0xc96f730 [0x18ecb38]>{contents = "test"}
4 : <CFString 0x17ca1c [0x18ecb38]>{contents = "description"} = <CFString 0xc9643f0 [0x18ecb38]>{contents = "test"}
}
Printing description of error:
Unknown format option

关于我哪里出错或将 NSDictionary 转换为 NSData 的替代方法有什么想法吗?

【问题讨论】:

    标签: iphone objective-c nsdictionary nsdata


    【解决方案1】:

    如文档所述,format 参数必须是以下参数之一:

    NSPropertyListOpenStepFormat
    NSPropertyListXMLFormat_v1_0
    NSPropertyListBinaryFormat_v1_0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多