如何使用Codable解码字典的JSON字典(具有不同的键?

问题描述 投票:0回答:1

我有以下简单的JSON:

{
    "201" :
    {
        "contryName" : "Albania",
        "countryCode" : "AL"
    },
    "202" :
    {
        "contryName" : "Andorra",
        "countryCode" : "AD"
    },
    ...
}

内部字典变成:

struct Mid : Codable
{
    var contryName: String
    var countryCode: String
}

但是后来我被困住了。我如何表示外部词典?

我想用MidString"201",...]创建一个"202"对象的字典作为结束>

我有以下简单的JSON:{“ 201”:{“ contryName”:“阿尔巴尼亚”,“ countryCode”:“ AL”},“ 202”:{“ contryName”:“安道尔”,“ countryCode”:。 ..

ios swift dictionary codable
1个回答
0
投票
  • 简单解决方案:

© www.soinside.com 2019 - 2024. All rights reserved.