【发布时间】:2018-01-31 09:49:06
【问题描述】:
我有以下表示 JSON 的结构:
struct Todo: Codable {
let ID: Int?
let LAST_DT_ADD: String?
let LAST_ID:Int?
}
当我以同样的方式使用解码时:
let decoder = JSONDecoder()
do {
let todo = try decoder.decode(Todo.self, from: responseData)
completionHandler(todo, nil)
} catch {
print("error trying to convert data to JSON")
print(error)
completionHandler(nil, error)
}
它可以正确解码,但是当我有小写 JSON 项目时(例如,我有 id、last_dt_add 和 last_id,而不是 ID、LAST_DT_ADD 和 LAST_ID),它不是解码对象。我需要做什么?如何支持大写和小写?
【问题讨论】:
标签: swift swift4 jsondecoder