ios - 如何在 Swift 中不向 NSJSONSerialization.JSONObjectWithData 传递任何选项

标签 ios swift swift2

在 Swift (2.0) 中反序列化 JSON 时,我不想传递任何选项。我最初尝试过:

NSJSONSerialization.JSONObjectWithData(data, options: nil)

但这并没有编译,我得到了错误:

Type NSJSONReadingOptions does not conform to protocol NilLiteralConvertible

枚举 NSJSONReadingOptions没有任何“无”选项,如果我不想要这些选项中的任何一个,我该怎么办?

最佳答案

在 swift 2 中,你应该使用空数组 [] 来指示 no options:

NSJSONSerialization.JSONObjectWithData(data, options: [])

关于ios - 如何在 Swift 中不向 NSJSONSerialization.JSONObjectWithData 传递任何选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31708828/

相关文章:

ios - 加载后 View 框架发生变化

ios - 为什么 iMessages 会更改我通过 UIActivityViewController 传递给它的 URL?

ios - 无法在 tabBarControllerVC 上以编程方式设置选项卡栏项目文本

ios - Kotlin/Native - 非法尝试访问非共享 <object>

ios - 如何通过点击 UITextView 中的特定字符来显示圆角灰色背景?

ios - 无法将类型 '__NSCFNumber' () 的值转换为 'NSArray' swift

ios - 我可以使用 NSXMLParser 保留一些不解析的部分吗?

ios - UILabel 垂直对齐

ios - UITable DidSelectRowAtIndexPath 未通过 segue 发送数据(意外发现为零)

ios - 使用 iPhone 作为 iBeacon 发射器