Swift - Convert [[String:Any?]] to Data

前端 未结 1 1608
难免孤独
难免孤独 2021-01-11 16:54

I have an [[String:Any]] object populated like:

var result : [[String : Any]] = [[String : Any]]()

And I need convert it to D

相关标签:
1条回答
  • 2021-01-11 17:29

    JSONEncoder can only encode objects whose type conforms to Encodable. If you want to encode Any to JSON, you need to use JSONSerialization to do that.

    let jsonData = try? JSONSerialization.data(withJSONObject:result)
    
    0 讨论(0)
提交回复
热议问题