将JSON映射为数组或对象

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

我有JSON,有时会显示有时是简单对象的数组

"ownersPeriod" : [
        {
          "dateTo" : "2013-06-17",
          "dateFrom" : "2012-09-15"
        },
        {
          "dateTo" : "2016-06-30",
          "dateFrom" : "2013-06-17"
        },
        {
          "dateTo" : "",
          "dateFrom" : "2016-06-30"
        }
      ],

"ownersPeriod" : {
        "dateTo" : "",
        "dateFrom" : "2008-03-29"
      },

如何将简单对象映射或转换为此类型数组

我使用对象映射器映射数组

public var ownersPeriodArray: [Model] = []
ios arrays json swift objectmapper
1个回答
0
投票

您可以在这里尝试此代码:http://online.swiftplayground.run/

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