使用某种数据标记解析JSON数据

时间:2016-11-11 13:00:21

标签: json swift

我试图将这个json变成这样的数组:

struct WeatherData{

    var timezone: timezone?
    var offset: Int?
    var temperature: Double
    var summary: String
    var WeatherIcon: icon
    var precipIcon: precipIcon
    var time: Double
    var precipIntensity: Double?
    var precipProbability: Double
    var precipProbabilityPercentage: Int
    var windSpeed: Double
    var humidity: Double
    var precipTypeText: String
}

struct WeatherDataArray{

    var weeklyWeather: [WeatherData]?

}

具体来说,我希望天气来自“每日”,但“data =”标签就是

但我想知道如何绕过“data =”标签。它是什么?是否有一种特殊的方式来处理这些?我是否必须使用字符串并删除前x个字母?和数组末尾的结束括号?

["latitude": 10, "longitude": 10, "offset": 1, "timezone": Africa/Lagos, "flags": {
    "isd-stations" =     (
        "650550-99999",
        "651340-99999"
    );
    sources =     (
        gfs,
        cmc,
        fnmoc,
        isd
    );
    units = si;
}, "daily": {
    data =     (
                {
            apparentTemperatureMax = "32.8";
            apparentTemperatureMaxTime = 1478872800;
            apparentTemperatureMin = "16.45";
            apparentTemperatureMinTime = 1478833200;
            cloudCover = "0.23";
            dewPoint = "0.43";
            humidity = "0.22";
            icon = "partly-cloudy-day";
            moonPhase = "0.38";
            ozone = "256.32";
            precipIntensity = 0;
            precipIntensityMax = 0;
            precipProbability = 0;
            pressure = "1010.07";
            summary = "Partly cloudy until afternoon.";
            sunriseTime = 1478841279;
            sunsetTime = 1478883373;
            temperatureMax = "35.52";
            temperatureMaxTime = 1478872800;
            temperatureMin = "16.45";
            temperatureMinTime = 1478833200;
            time = 1478818800;
            windBearing = 13;
            windSpeed = "1.84";
        },
                {
            apparentTemperatureMax = "34.37";
            apparentTemperatureMaxTime = 1478955600;
            apparentTemperatureMin = "14.67";
            apparentTemperatureMinTime = 1478923200;
            cloudCover = "0.22";
            dewPoint = "2.07";
            humidity = "0.26";
            icon = "partly-cloudy-day";
            moonPhase = "0.42";
            ozone = "255.7";
            precipIntensity = 0;
            precipIntensityMax = 0;
            precipProbability = 0;
            pressure = "1009.42";
            summary = "Partly cloudy in the morning.";
            sunriseTime = 1478927700;
            sunsetTime = 1478969769;
            temperatureMax = "37.03";
            temperatureMaxTime = 1478955600;
            temperatureMin = "14.67";
            temperatureMinTime = 1478923200;
            time = 1478905200;
            windBearing = 42;
            windSpeed = "1.41";
        },
                {
            apparentTemperatureMax = "34.63";
            apparentTemperatureMaxTime = 1479045600;
            apparentTemperatureMin = "15.27";
            apparentTemperatureMinTime = 1479006000;
            cloudCover = "0.39";
            dewPoint = "1.76";
            humidity = "0.24";
            icon = "partly-cloudy-night";
            moonPhase = "0.46";
            ozone = "253.31";
            precipIntensity = 0;
            precipIntensityMax = 0;
            precipProbability = 0;
            pressure = "1008.89";
            summary = "Mostly cloudy starting in the afternoon.";
            sunriseTime = 1479014121;
            sunsetTime = 1479056166;
            temperatureMax = "37.37";
            temperatureMaxTime = 1479045600;
            temperatureMin = "15.27";
            temperatureMinTime = 1479006000;
            time = 1478991600;
            windBearing = 36;
            windSpeed = "2.22";
        }]

谢谢你们!

0 个答案:

没有答案