首页 文章

如何使用AESON从Json文件中提取list []

提问于
浏览
-4

我有这个JSON代码

{
      "cod": "200",
"message": 0.0205,
"cnt": 40,
"list": [{
    "dt": 1529690400,
    "main": {
        "temp": 294.89,
        "temp_min": 289.889,
        "temp_max": 294.89,
        "pressure": 875.6,
        "sea_level": 1022.36,
        "grnd_level": 875.6,
        "humidity": 73,
        "temp_kf": 5
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 32
    },
    "wind": {
        "speed": 0.76,
        "deg": 355
    },
    "rain": {
        "3h": 0.0625
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-22 18:00:00"
}, {
    "dt": 1529701200,
    "main": {
        "temp": 291.2,
        "temp_min": 287.449,
        "temp_max": 291.2,
        "pressure": 875.14,
        "sea_level": 1022.14,
        "grnd_level": 875.14,
        "humidity": 82,
        "temp_kf": 3.75
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "02n"
    }],
    "clouds": {
        "all": 8
    },
    "wind": {
        "speed": 0.76,
        "deg": 7.00244
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-22 21:00:00"
}, {
    "dt": 1529712000,
    "main": {
        "temp": 288.19,
        "temp_min": 285.69,
        "temp_max": 288.19,
        "pressure": 874.94,
        "sea_level": 1022.29,
        "grnd_level": 874.94,
        "humidity": 88,
        "temp_kf": 2.5
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.26,
        "deg": 237
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-23 00:00:00"
}, {
    "dt": 1529722800,
    "main": {
        "temp": 288.65,
        "temp_min": 287.398,
        "temp_max": 288.65,
        "pressure": 875.18,
        "sea_level": 1022.74,
        "grnd_level": 875.18,
        "humidity": 86,
        "temp_kf": 1.25
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.37,
        "deg": 91.5048
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-23 03:00:00"
}, {
    "dt": 1529733600,
    "main": {
        "temp": 294.069,
        "temp_min": 294.069,
        "temp_max": 294.069,
        "pressure": 874.97,
        "sea_level": 1021.62,
        "grnd_level": 874.97,
        "humidity": 73,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.6,
        "deg": 237.003
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-23 06:00:00"
}, {
    "dt": 1529744400,
    "main": {
        "temp": 297.09,
        "temp_min": 297.09,
        "temp_max": 297.09,
        "pressure": 874.08,
        "sea_level": 1020,
        "grnd_level": 874.08,
        "humidity": 70,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.85,
        "deg": 306.003
    },
    "rain": {
        "3h": 0.255
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-23 09:00:00"
}, {
    "dt": 1529755200,
    "main": {
        "temp": 298.961,
        "temp_min": 298.961,
        "temp_max": 298.961,
        "pressure": 873.46,
        "sea_level": 1019.23,
        "grnd_level": 873.46,
        "humidity": 53,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 48
    },
    "wind": {
        "speed": 0.76,
        "deg": 251.002
    },
    "rain": {
        "3h": 0.04
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-23 12:00:00"
}, {
    "dt": 1529766000,
    "main": {
        "temp": 294.815,
        "temp_min": 294.815,
        "temp_max": 294.815,
        "pressure": 874.28,
        "sea_level": 1020.19,
        "grnd_level": 874.28,
        "humidity": 58,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 76
    },
    "wind": {
        "speed": 1.86,
        "deg": 352.501
    },
    "rain": {
        "3h": 0.185
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-23 15:00:00"
}, {
    "dt": 1529776800,
    "main": {
        "temp": 290.337,
        "temp_min": 290.337,
        "temp_max": 290.337,
        "pressure": 875.08,
        "sea_level": 1021.69,
        "grnd_level": 875.08,
        "humidity": 73,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 36
    },
    "wind": {
        "speed": 0.76,
        "deg": 313.509
    },
    "rain": {
        "3h": 0.02
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-23 18:00:00"
}, {
    "dt": 1529787600,
    "main": {
        "temp": 288.89,
        "temp_min": 288.89,
        "temp_max": 288.89,
        "pressure": 875.39,
        "sea_level": 1022.49,
        "grnd_level": 875.39,
        "humidity": 81,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 56
    },
    "wind": {
        "speed": 1.01,
        "deg": 40.0106
    },
    "rain": {
        "3h": 0.055
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-23 21:00:00"
}, {
    "dt": 1529798400,
    "main": {
        "temp": 287.14,
        "temp_min": 287.14,
        "temp_max": 287.14,
        "pressure": 875.88,
        "sea_level": 1023.4,
        "grnd_level": 875.88,
        "humidity": 88,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.56,
        "deg": 269.504
    },
    "rain": {
        "3h": 0.0050000000000001
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-24 00:00:00"
}, {
    "dt": 1529809200,
    "main": {
        "temp": 287.812,
        "temp_min": 287.812,
        "temp_max": 287.812,
        "pressure": 876.56,
        "sea_level": 1024.3,
        "grnd_level": 876.56,
        "humidity": 86,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.71,
        "deg": 277.505
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-24 03:00:00"
}, {
    "dt": 1529820000,
    "main": {
        "temp": 293.984,
        "temp_min": 293.984,
        "temp_max": 293.984,
        "pressure": 876.57,
        "sea_level": 1023.26,
        "grnd_level": 876.57,
        "humidity": 71,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.41,
        "deg": 234.503
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-24 06:00:00"
}, {
    "dt": 1529830800,
    "main": {
        "temp": 298.045,
        "temp_min": 298.045,
        "temp_max": 298.045,
        "pressure": 875.39,
        "sea_level": 1021.2,
        "grnd_level": 875.39,
        "humidity": 63,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.62,
        "deg": 244.502
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-24 09:00:00"
}, {
    "dt": 1529841600,
    "main": {
        "temp": 299.666,
        "temp_min": 299.666,
        "temp_max": 299.666,
        "pressure": 874.25,
        "sea_level": 1019.85,
        "grnd_level": 874.25,
        "humidity": 54,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.77,
        "deg": 13.5015
    },
    "rain": {
        "3h": 0.11
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-24 12:00:00"
}, {
    "dt": 1529852400,
    "main": {
        "temp": 295.301,
        "temp_min": 295.301,
        "temp_max": 295.301,
        "pressure": 874.92,
        "sea_level": 1021.12,
        "grnd_level": 874.92,
        "humidity": 60,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 80
    },
    "wind": {
        "speed": 1.51,
        "deg": 352.5
    },
    "rain": {
        "3h": 0.41
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-24 15:00:00"
}, {
    "dt": 1529863200,
    "main": {
        "temp": 291.351,
        "temp_min": 291.351,
        "temp_max": 291.351,
        "pressure": 877.27,
        "sea_level": 1024.08,
        "grnd_level": 877.27,
        "humidity": 69,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 88
    },
    "wind": {
        "speed": 0.96,
        "deg": 202.001
    },
    "rain": {
        "3h": 0.16
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-24 18:00:00"
}, {
    "dt": 1529874000,
    "main": {
        "temp": 289.244,
        "temp_min": 289.244,
        "temp_max": 289.244,
        "pressure": 877.29,
        "sea_level": 1024.89,
        "grnd_level": 877.29,
        "humidity": 83,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 12
    },
    "wind": {
        "speed": 0.86,
        "deg": 2.00073
    },
    "rain": {
        "3h": 0.245
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-24 21:00:00"
}, {
    "dt": 1529884800,
    "main": {
        "temp": 287.522,
        "temp_min": 287.522,
        "temp_max": 287.522,
        "pressure": 877.08,
        "sea_level": 1024.9,
        "grnd_level": 877.08,
        "humidity": 88,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10n"
    }],
    "clouds": {
        "all": 80
    },
    "wind": {
        "speed": 0.75,
        "deg": 318.504
    },
    "rain": {
        "3h": 0.075
    },
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-25 00:00:00"
}, {
    "dt": 1529895600,
    "main": {
        "temp": 288.908,
        "temp_min": 288.908,
        "temp_max": 288.908,
        "pressure": 877.54,
        "sea_level": 1025.36,
        "grnd_level": 877.54,
        "humidity": 83,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.05,
        "deg": 262.003
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-25 03:00:00"
}, {
    "dt": 1529906400,
    "main": {
        "temp": 294.535,
        "temp_min": 294.535,
        "temp_max": 294.535,
        "pressure": 877.28,
        "sea_level": 1024.11,
        "grnd_level": 877.28,
        "humidity": 69,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.13,
        "deg": 219.503
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-25 06:00:00"
}, {
    "dt": 1529917200,
    "main": {
        "temp": 298.43,
        "temp_min": 298.43,
        "temp_max": 298.43,
        "pressure": 876.1,
        "sea_level": 1022.05,
        "grnd_level": 876.1,
        "humidity": 62,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.47,
        "deg": 209.002
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-25 09:00:00"
}, {
    "dt": 1529928000,
    "main": {
        "temp": 300.707,
        "temp_min": 300.707,
        "temp_max": 300.707,
        "pressure": 874.91,
        "sea_level": 1020.42,
        "grnd_level": 874.91,
        "humidity": 53,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 8
    },
    "wind": {
        "speed": 1.12,
        "deg": 91.0061
    },
    "rain": {
        "3h": 0.085
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-25 12:00:00"
}, {
    "dt": 1529938800,
    "main": {
        "temp": 300.111,
        "temp_min": 300.111,
        "temp_max": 300.111,
        "pressure": 874.29,
        "sea_level": 1020.03,
        "grnd_level": 874.29,
        "humidity": 45,
        "temp_kf": 0
    },
    "weather": [{
        "id": 500,
        "main": "Rain",
        "description": "light rain",
        "icon": "10d"
    }],
    "clouds": {
        "all": 8
    },
    "wind": {
        "speed": 1.41,
        "deg": 63.0023
    },
    "rain": {
        "3h": 0.0049999999999999
    },
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-25 15:00:00"
}, {
    "dt": 1529949600,
    "main": {
        "temp": 295.261,
        "temp_min": 295.261,
        "temp_max": 295.261,
        "pressure": 874.79,
        "sea_level": 1021.26,
        "grnd_level": 874.79,
        "humidity": 45,
        "temp_kf": 0
    },
    "weather": [{
        "id": 802,
        "main": "Clouds",
        "description": "scattered clouds",
        "icon": "03n"
    }],
    "clouds": {
        "all": 48
    },
    "wind": {
        "speed": 3.2,
        "deg": 35.0003
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-25 18:00:00"
}, {
    "dt": 1529960400,
    "main": {
        "temp": 291.742,
        "temp_min": 291.742,
        "temp_max": 291.742,
        "pressure": 874.55,
        "sea_level": 1021.47,
        "grnd_level": 874.55,
        "humidity": 52,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.66,
        "deg": 32.0015
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-25 21:00:00"
}, {
    "dt": 1529971200,
    "main": {
        "temp": 289.406,
        "temp_min": 289.406,
        "temp_max": 289.406,
        "pressure": 874.74,
        "sea_level": 1021.87,
        "grnd_level": 874.74,
        "humidity": 60,
        "temp_kf": 0
    },
    "weather": [{
        "id": 802,
        "main": "Clouds",
        "description": "scattered clouds",
        "icon": "03n"
    }],
    "clouds": {
        "all": 36
    },
    "wind": {
        "speed": 1.36,
        "deg": 11.5036
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-26 00:00:00"
}, {
    "dt": 1529982000,
    "main": {
        "temp": 290.344,
        "temp_min": 290.344,
        "temp_max": 290.344,
        "pressure": 875.24,
        "sea_level": 1022.61,
        "grnd_level": 875.24,
        "humidity": 68,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.07,
        "deg": 25.501
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-26 03:00:00"
}, {
    "dt": 1529992800,
    "main": {
        "temp": 296.669,
        "temp_min": 296.669,
        "temp_max": 296.669,
        "pressure": 875.14,
        "sea_level": 1021.37,
        "grnd_level": 875.14,
        "humidity": 58,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.11,
        "deg": 225.5
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-26 06:00:00"
}, {
    "dt": 1530003600,
    "main": {
        "temp": 300.4,
        "temp_min": 300.4,
        "temp_max": 300.4,
        "pressure": 873.55,
        "sea_level": 1019,
        "grnd_level": 873.55,
        "humidity": 52,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.12,
        "deg": 237.501
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-26 09:00:00"
}, {
    "dt": 1530014400,
    "main": {
        "temp": 302.474,
        "temp_min": 302.474,
        "temp_max": 302.474,
        "pressure": 872.27,
        "sea_level": 1017.3,
        "grnd_level": 872.27,
        "humidity": 42,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.52,
        "deg": 234
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-26 12:00:00"
}, {
    "dt": 1530025200,
    "main": {
        "temp": 300.919,
        "temp_min": 300.919,
        "temp_max": 300.919,
        "pressure": 872.19,
        "sea_level": 1017.17,
        "grnd_level": 872.19,
        "humidity": 37,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "02d"
    }],
    "clouds": {
        "all": 8
    },
    "wind": {
        "speed": 1.65,
        "deg": 266.501
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-26 15:00:00"
}, {
    "dt": 1530036000,
    "main": {
        "temp": 294.477,
        "temp_min": 294.477,
        "temp_max": 294.477,
        "pressure": 872.56,
        "sea_level": 1018.52,
        "grnd_level": 872.56,
        "humidity": 55,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.92,
        "deg": 342.504
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-26 18:00:00"
}, {
    "dt": 1530046800,
    "main": {
        "temp": 290.615,
        "temp_min": 290.615,
        "temp_max": 290.615,
        "pressure": 873.13,
        "sea_level": 1019.46,
        "grnd_level": 873.13,
        "humidity": 51,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.81,
        "deg": 20.505
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-26 21:00:00"
}, {
    "dt": 1530057600,
    "main": {
        "temp": 288.302,
        "temp_min": 288.302,
        "temp_max": 288.302,
        "pressure": 873.42,
        "sea_level": 1020.19,
        "grnd_level": 873.42,
        "humidity": 68,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01n"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.42,
        "deg": 10.0019
    },
    "rain": {},
    "sys": {
        "pod": "n"
    },
    "dt_txt": "2018-06-27 00:00:00"
}, {
    "dt": 1530068400,
    "main": {
        "temp": 290.209,
        "temp_min": 290.209,
        "temp_max": 290.209,
        "pressure": 873.93,
        "sea_level": 1020.72,
        "grnd_level": 873.93,
        "humidity": 65,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.66,
        "deg": 36
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-27 03:00:00"
}, {
    "dt": 1530079200,
    "main": {
        "temp": 297.644,
        "temp_min": 297.644,
        "temp_max": 297.644,
        "pressure": 873.95,
        "sea_level": 1019.72,
        "grnd_level": 873.95,
        "humidity": 52,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.61,
        "deg": 230
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-27 06:00:00"
}, {
    "dt": 1530090000,
    "main": {
        "temp": 301.518,
        "temp_min": 301.518,
        "temp_max": 301.518,
        "pressure": 873.16,
        "sea_level": 1018.11,
        "grnd_level": 873.16,
        "humidity": 45,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.51,
        "deg": 309.5
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-27 09:00:00"
}, {
    "dt": 1530100800,
    "main": {
        "temp": 303.24,
        "temp_min": 303.24,
        "temp_max": 303.24,
        "pressure": 872.25,
        "sea_level": 1016.8,
        "grnd_level": 872.25,
        "humidity": 32,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 1.32,
        "deg": 304.5
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-27 12:00:00"
}, {
    "dt": 1530111600,
    "main": {
        "temp": 302.008,
        "temp_min": 302.008,
        "temp_max": 302.008,
        "pressure": 871.75,
        "sea_level": 1016.41,
        "grnd_level": 871.75,
        "humidity": 33,
        "temp_kf": 0
    },
    "weather": [{
        "id": 800,
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    }],
    "clouds": {
        "all": 0
    },
    "wind": {
        "speed": 0.75,
        "deg": 260.003
    },
    "rain": {},
    "sys": {
        "pod": "d"
    },
    "dt_txt": "2018-06-27 15:00:00"
}],
"city": {
    "id": 616052,
    "name": "Yerevan",
    "coord": {
        "lat": 40.1776,
        "lon": 44.5126
    },
    "country": "AM",
    "population": 1093485
}

}

如何从此列表中提取项目?我需要使用AESON . 例如,我该如何提取这个?
{"temp":288.89,"temp_min":288.89,"temp_max":288.89,"pressure":875.39,"sea_level":1022.49,"grnd_level":875.39,"humidity":81,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain", "icon":"10n"}],"clouds":{"all":56},"wind":{"speed":1.01,"deg":40.0106},"rain":{"3h":0.055},"sys":{"pod":"n"},"dt_txt":"2018-06-23 21:00:00"},{"dt": 1529798400,"main":

我的代码:

{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

module PrepareAnswer where

import           Data.Aeson
import qualified Data.ByteString.Lazy as BSL
import           Data.Maybe           (fromMaybe)
import           Data.Text
import           Data.Time.Clock
import           GHC.Generics 
import           Network.HTTP.Client

data MainWeatherInfo = MainWeatherInfo
  { mainInfo :: MainInfo
  , list     :: ListWeatherInfo
  } deriving (Show, Generic)

data ListWeatherInfo = ListWeatherInfo
{ temper     :: Double
,  temp_min  :: Double
, temp_max   :: Double
, pressure1  :: Double
, sea_level  :: Double
, grnd_level :: Double
, humidity   :: Int
, temp_kf    :: Double
, dt_txt     :: UTCTime
} deriving (Show, Generic)

instance ToJSON MainWeatherInfo where
  toJSON = genericToJSON defaultOptions { fieldLabelModifier = Prelude.take 4 }

instance FromJSON MainWeatherInfo where
  parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = Prelude.take 4 }

instance ToJSON   ListWeatherInfo
instance FromJSON ListWeatherInfo

data MainInfo = MainInfo
  { temp     :: Double
  , pressure :: Int
  } deriving ( Show
             , Generic
             , ToJSON
             , FromJSON
             )

prepareAnswer :: Response BSL.ByteString -> Text
prepareAnswer response = Data.Text.pack finalPhrase
    where
        finalPhrase   = prepareValues weatherValues
        weatherValues = extractValues . responseBody $ response

extractValues :: BSL.ByteString -> MainWeatherInfo
extractValues rawJSON =
    let result  = decode rawJSON :: Maybe MainWeatherInfo
    in fromMaybe (error "Invalid JSON!") result

prepareValues :: MainWeatherInfo -> String
prepareValues (MainWeatherInfo dataWeNeed forecastList) =
    "The expected temperature is: "
    ++ show (temp dataWeNeed )
    ++ " degrees Celsius, atmospheric pressure is "
    ++ show (pressure dataWeNeed)
    ++ " mm/hg"

1 回答

  • 0

    你可能想要 list :: [ListWeatherInfo] . 目前它预计 list 将是一个记录,但在示例数据中它是一个json数组 .

相关问题