如何使用Codable在Swift中获取JSON数组值

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

我无法从以下JSON获取方向值:

"routeOptions": [
        {
          "name": "Jubilee",
          "directions": [
            "Wembley Park Underground Station",
            "Stanmore Underground Station"
          ],
          "lineIdentifier": {
            "id": "jubilee",
            "name": "Jubilee",
            "uri": "/Line/jubilee",
            "type": "Line",
            "routeType": "Unknown",
            "status": "Unknown"
          }
        }
      ]

我相信路线是一个JSON数组,此刻我正在使用如下Codable。我已经设法获得routeOptions名称,但由于没有特定的键变量,因此似乎无法弄清楚如何获得路线指示。请有人帮忙吗?

struct RouteOptions: Codable {

let name: String?
let directions: [Directions]?

init(name: String, directions: [Directions]) {
    self.name = name
    self.directions = directions
}}

struct Directions: Codable {}
arrays json swift codable
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.