以下代码无法在Swift 2.0中编译
var eventsIds : [CalendarEventLink?] = [CalendarEventLink?](count: 5, repeatedValue: nil)
var data = try NSJSONSerialization.dataWithJSONObject(eventsIds, options: [])
我收到错误:
' [?CalendarEventLink]'不能转换为' [AnyObject]'
如何在swift中将数组序列化为json?
答案 0 :(得分:1)
var eventsIds : [CalendarEventLink] = []
var data = try NSJSONSerialization.dataWithJSONObject(eventsIds, options: [])
如上面的评论中所述,您无法将可选项目数组发送到[AnyObject]