小编Hon*_*Qii的帖子

Swift 4 JSONEncoder 无法编码 String 或 Int,但它们遵循 Codable 协议

let encoder = JSONEncoder()

do {
   let encodData = try encoder.encode("test string") // same as Int type
   print(encodData) // nil
} catch let err {
   print(err.localizedDescription) // The data couldn’t be written because it isn’t in the correct format.
}
Run Code Online (Sandbox Code Playgroud)

如何编码这些类型值

swift jsonencoder

4
推荐指数
1
解决办法
2135
查看次数

标签 统计

jsonencoder ×1

swift ×1