以下代码无法在 Swift 2.0 中编译
var eventsIds : [CalendarEventLink?] = [CalendarEventLink?](count: 5, repeatedValue: nil)
var data = try NSJSONSerialization.dataWithJSONObject(eventsIds, options: [])
我遇到错误:
'[CalendarEventLink?]' is not convertible to '[AnyObject]'
如何在 swift 中将数组序列化为 json?
最佳答案
var eventsIds : [CalendarEventLink] = []
var data = try NSJSONSerialization.dataWithJSONObject(eventsIds, options: [])
如上面的评论所述,您不能将可选项目数组发送到 [AnyObject]
关于ios - 将swift数组转换为对象以进行json序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33042625/