我的 Api(json) 看起来像这样:
"timezone": "America/Los_Angeles",
"currently": {
"time": 1534941429,
...
},
使用我的代码,我可以访问时区,如下所示:
timezone = try container.decode(Double.self, forKey: .timezone)
但是我如何深入了解 json 文件的层次结构并访问时间?
最佳答案
struct Currently: Codable {
let time: Int
...
}
let myStructDictionary = try container.decode([String: Currently].self, from: json)
myStructDictionary.forEach { print("\($0.key): \($0.value)") }
希望这有帮助。
关于ios - 核心数据&解码: Go one hierarchy step further in json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51968000/