根目录下的 Codable Handle 动态密钥

Codable Handle dynamic key at root

我已经看过几个类似的问题,但我有不同的 JSON

所以我 JSON 看起来像下面

var json = """
{
"Array1": [
{
"FinancialYear": "17-18"

}],
"Array2": [
{
"FinancialYear": "17-18"
}]
}
"""

问题是 Array1Array2 键似乎是动态的,它位于 ROOT 并且可以更像 Array3、Array4等等

我想使用 Codable,但由于根目录 (Array1,Array2) 中的动态密钥,我无法摆脱它。

这是我试过但没有用的结构

struct CodableJSON: Codable {
    var response:[String:[ArrayInside]]
    enum CodingKeys: String, CodingKey   {
        case response = "What should I write here ?" // What should be here ? 
    }

}

在这种情况下,仅声明 ArrayInside 结构

struct ArrayInside: Decodable {
   ...
}

并将根对象解码为字典

let result = try JSONDecoder().decode([String:[ArrayInside]].self, from: data)