小编Mas*_*sta的帖子

带有动态键的Swift Codable

我有JSON结构为:

"periods": {
    "2018-06-07": [
      {
        "firstName": "Test1",
        "lastName": "Test1"
      }
    ],
    "2018-06-06": [
      {
        "firstName": "Test1",
        "lastName": "Test1"
      }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我试图这样解析:

public struct Schedule: Codable {
    public let periods: Periods
}

public struct Periods: Codable {
    public let unknown: [Inner]

    public struct Inner: Codable {
        public let firstName: String
        public let lastName: String
    }

    private struct CustomCodingKeys: CodingKey {
        var stringValue: String
        init?(stringValue: String) {
            self.stringValue = stringValue
        }

        var intValue: Int?
        init?(intValue: Int) {
            return …
Run Code Online (Sandbox Code Playgroud)

json swift swift4 codable

4
推荐指数
2
解决办法
4342
查看次数

标签 统计

codable ×1

json ×1

swift ×1

swift4 ×1