【发布时间】:2019-08-28 14:19:22
【问题描述】:
假设我收到了来自 Weather API 的响应。
{
"2019-08-27 19:00:00":{
"temperature":{
"ground":292,
},
"pressure":{
"see_level":101660
}
},
"2019-08-27 23:00:00":{
"temperature":{
"ground":292,
},
"pressure":{
"see_level":101660
}
}
}
我有 Result 数据类型,其中包含一个温度属性,该属性可以包含地面对象中的任何 JSON 字典
struct Result: Codable {
let ????: [String: Any]
}
struct Temperature: Codable {
let ground: Int
}
有谁知道如何使用 Codable 协议来实现这一点,以便在不使用其密钥的情况下正确解析每个预测?
【问题讨论】: