How to extract list [] from Json file with AESON - json
I have this JSON code
{
"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
}
}
How do I extract an item from this list?
I need to use AESON.
for example, how do I extract this?
{"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":
My code:
{-# 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"
You probably want list :: [ListWeatherInfo]. Currently it expects that list will be a record, but in the example data it is a json array.
Related
How can I iterate over each item and render on the screen?
I've been trying to iterate over each item for forecast data and can't figure out where the outputs are coming from.. I'm only trying to iterate over temperature, pressure, place name, humidity, wind speed and feels like.. Json { "cod": "200", "message": 0, "cnt": 40, "list": [ { "dt": 1641124800, "main": { "temp": 11.74, "feels_like": 11.08, "temp_min": 11.74, "temp_max": 12, "pressure": 1012, "sea_level": 1012, "grnd_level": 1008, "humidity": 81, "temp_kf": -0.26 }, "weather": [ { "id": 803, "main": "Clouds", "description": "broken clouds", "icon": "04d" } ], "clouds": { "all": 75 }, "wind": { "speed": 5.3, "deg": 229, "gust": 11.75 }, "visibility": 10000, "pop": 0, "sys": { "pod": "d" }, "dt_txt": "2022-01-02 12:00:00" }, { "dt": 1641135600, "main": { "temp": 11.86, "feels_like": 11.11, "temp_min": 11.86, "temp_max": 12.09, "pressure": 1011, "sea_level": 1011, "grnd_level": 1006, "humidity": 77, "temp_kf": -0.23 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10d" } ], "clouds": { "all": 83 }, "wind": { "speed": 6.45, "deg": 223, "gust": 15.9 }, "visibility": 10000, "pop": 0.7, "rain": { "3h": 0.6 }, "sys": { "pod": "d" }, "dt_txt": "2022-01-02 15:00:00" }, { "dt": 1641146400, "main": { "temp": 11.29, "feels_like": 10.43, "temp_min": 11.06, "temp_max": 11.29, "pressure": 1011, "sea_level": 1011, "grnd_level": 1007, "humidity": 75, "temp_kf": 0.23 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10n" } ], "clouds": { "all": 92 }, "wind": { "speed": 6.1, "deg": 250, "gust": 13.97 }, "visibility": 10000, "pop": 0.94, "rain": { "3h": 1.01 }, "sys": { "pod": "n" }, "dt_txt": "2022-01-02 18:00:00" }, { "dt": 1641157200, "main": { "temp": 9.54, "feels_like": 6.37, "temp_min": 9.54, "temp_max": 9.54, "pressure": 1012, "sea_level": 1012, "grnd_level": 1009, "humidity": 76, "temp_kf": 0 }, "weather": [ { "id": 802, "main": "Clouds", "description": "scattered clouds", "icon": "03n" } ], "clouds": { "all": 36 }, "wind": { "speed": 6.93, "deg": 244, "gust": 14.72 }, "visibility": 10000, "pop": 0, "sys": { "pod": "n" }, "dt_txt": "2022-01-02 21:00:00" }, { "dt": 1641546000, "main": { "temp": 3.96, "feels_like": 0.41, "temp_min": 3.96, "temp_max": 3.96, "pressure": 1010, "sea_level": 1010, "grnd_level": 1007, "humidity": 82, "temp_kf": 0 }, "weather": [ { "id": 804, "main": "Clouds", "description": "overcast clouds", "icon": "04d" } ], "clouds": { "all": 100 }, "wind": { "speed": 4.29, "deg": 239, "gust": 11.29 }, "visibility": 10000, "pop": 0.02, "sys": { "pod": "d" }, "dt_txt": "2022-01-07 09:00:00" } ], "city": { "id": 2643743, "name": "London", "coord": { "lat": 51.5085, "lon": -0.1257 }, "country": "GB", "population": 1000000, "timezone": 0, "sunrise": 1641110761, "sunset": 1641139355 } } in forecast.dart import 'package:forecast/models/weather_data.dart'; class ForecastData { final List list; ForecastData({required this.list}); factory ForecastData.fromJson(Map<String, dynamic> json) { var list = json['list']?.map((e) => e)?.toList(growable: true) ?? []; List weatherData = []; list.forEach((e) { WeatherData w = WeatherData( placeName: json['city']['name'], temperature: e['main']['temp'], feels_like: e['main']["feels_like"], pressure: e['main']['pressure'], humidity: e['main']['humidity'], wind_speed: e['wind']['speed']); weatherData.add(w); print(weatherData.toList()); }); return ForecastData(list: weatherData); } } weatherdata.dart class WeatherData { String? placeName; num? temperature; num? feels_like; num? pressure; num? humidity; num? wind_speed; WeatherData({ this.placeName, this.temperature, this.feels_like, this.pressure, this.humidity, this.wind_speed, }); #override String toString() => '${placeName ?? 'unknown'}${feels_like ?? 'unknown'}${temperature ?? 'unknown'}${pressure ?? 'unknown'}${humidity ?? 'unknown'}${wind_speed ?? 'unknown'}'; WeatherData.fromJson(Map<String, dynamic> json) { placeName = json['city']['name']; temperature = json['list'][0]['main']['temp']; feels_like = json['list'][0]['main']['temp']; pressure = json['list'][0]['main']['temp']; humidity = json['list'][0]['main']['temp']; wind_speed = json['list'][0]['main']['temp']; } } output I/flutter (25471): [London11.0811.741012815.3] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45, London10.4311.291011756.1] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45, London10.4311.291011756.1, London6.379.541012766.93] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45, London10.4311.291011756.1, London6.379.541012766.93, London6.229.481013757.18] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45, London10.4311.291011756.1, London6.379.541012766.93, London6.229.481013757.18, London6.039.051013796.02] I/flutter (25471): [London11.0811.741012815.3, London11.1111.861011776.45, London10.4311.291011756.1, London6.379.541012766.93, London6.229.481013757.18, London6.039.051013796.02, London5.698.681012795.66] I can't figure out where the problem is..why is my output iterating like this? I just need to iterate over each item and print out each item each time please help!
in forecast.dart, You are printing the whole weatherData list in the iterator list.forEach. Try changing , print(weatherData.toList()); to, print(w); And put some spaces in your toString ${placeName ?? 'unknown'} ${feels_like ?? 'unknown'} ${te... so that you can see where one number ends and the next starts.
I think that you shoul lose the map and review the fromJson parameters... WeatherData.fromJson(Map<String, dynamic> json) { placeName = json['city']['name']; temperature = json['list'][0]['main']['temp']; feels_like = json['list'][0]['main']['temp']; pressure = json['list'][0]['main']['temp']; humidity = json['list'][0]['main']['temp']; wind_speed = json['list'][0]['main']['temp']; }
Problem getting data from json through http with riverpod
I have this json: { "coord": { "lon": -3.7026, "lat": 40.4165 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01n" } ], "base": "stations", "main": { "temp": 297.84, "feels_like": 297.62, "temp_min": 294.82, "temp_max": 299.94, "pressure": 1017, "humidity": 48 }, "visibility": 10000, "wind": { "speed": 1.34, "deg": 270, "gust": 2.68 }, "clouds": { "all": 0 }, "dt": 1631051279, "sys": { "type": 2, "id": 2007545, "country": "ES", "sunrise": 1630993686, "sunset": 1631039875 }, "timezone": 7200, "id": 3117735, "name": "Madrid", "cod": 200 } with this link: http://api.openweathermap.org/data/2.5/weather?id=3117735&appid=899fc742471c1a7623a573d0bc7ad85b I want to get the data, to make that I created the class with a json convert, and get want to get the data through a json.decode: Future<Madrid> fetchMadrid() async { final response = await http .get(Uri.parse('http://api.openweathermap.org/data/2.5/weather?id=3117735&appid=899fc742471c1a7623a573d0bc7ad85b')) .timeout(const Duration(seconds: 2)); if (response.statusCode == 200) { return parseMadrid(response.body); } else { throw Exception('Error'); } } Madrid parseMadrid(String response) { var list = json.decode(response); Madrid photos = Madrid.fromJson(list); return photos; } final madridStateProvider = FutureProvider<Madrid>((ref) async { return fetchMadridLocal(); }); and get the data through a Future Provider with riverbed. I get the error: Expected a value of type 'Coord', but got one of type '_JsonMap'
How to group flight segments/legs in Bargain Finder Max?
I am trying to search for flights between two places in Sabre using BargainFindermax API. The API provides me with a list of all flights. However, there is no direct relation to which of the flights are linked. For example, I searched for flights between BLR > LCY. The response I got included flights for AMS > LCY, BLR > DEL, BLR > DEL, DEL > AMS, AMS > LCY. From this, I can construct the following route BLR > DEL > AMS > LCY. But there are two flights for BLR > DEL and AMS > LCY. How can I identify which of these flights are related? Here is the complete JSON response, { "groupedItineraryResponse": { "version": "5.2.0", "messages": [ { "severity": "Info", "type": "WORKERTHREAD", "code": "TRANSACTIONID", "text": "2074398531853061390" }, { "severity": "Info", "type": "SERVER", "code": "ASE032LPSCIL9UM.IDM.SGDCCERT.SABRE.COM", "text": "27036" }, { "severity": "Info", "type": "DRE", "code": "RULEID", "text": "17203" }, { "severity": "Info", "type": "DEFAULT", "code": "RULEID", "text": "25238" } ], "statistics": { "itineraryCount": 2 }, "scheduleDescs": [ { "id": 1, "frequency": "*MTWTFS", "stopCount": 0, "eTicketable": true, "totalMilesFlown": 257, "departure": { "airport": "AMS", "city": "AMS", "country": "NL", "time": "08:45:00+02:00" }, "arrival": { "airport": "LCY", "city": "LON", "country": "GB", "time": "08:50:00+01:00" }, "carrier": { "marketing": "KL", "marketingFlightNumber": 985, "operating": "KL", "operatingFlightNumber": 985, "codeShared": "/KLM CITYHOPPER", "equipment": { "code": "E90", "typeForFirstLeg": "N", "typeForLastLeg": "N" } } }, { "id": 2, "trafficRestriction": "G", "frequency": "SMTWTFS", "stopCount": 0, "eTicketable": true, "totalMilesFlown": 1058, "departure": { "airport": "BLR", "city": "BLR", "country": "IN", "time": "19:50:00+05:30" }, "arrival": { "airport": "DEL", "city": "DEL", "country": "IN", "time": "22:50:00+05:30", "terminal": "3" }, "carrier": { "marketing": "KL", "marketingFlightNumber": 3798, "operating": "9W", "operatingFlightNumber": 812, "disclosure": "9W", "equipment": { "code": "73H", "typeForFirstLeg": "N", "typeForLastLeg": "N" } } }, { "id": 3, "trafficRestriction": "G", "frequency": "SMTWTFS", "stopCount": 0, "eTicketable": true, "totalMilesFlown": 1058, "departure": { "airport": "BLR", "city": "BLR", "country": "IN", "time": "18:55:00+05:30" }, "arrival": { "airport": "DEL", "city": "DEL", "country": "IN", "time": "22:00:00+05:30", "terminal": "3" }, "carrier": { "marketing": "KL", "marketingFlightNumber": 3703, "operating": "9W", "operatingFlightNumber": 833, "disclosure": "9W", "equipment": { "code": "738", "typeForFirstLeg": "N", "typeForLastLeg": "N" } } }, { "id": 4, "frequency": "*M**T**", "stopCount": 0, "eTicketable": true, "totalMilesFlown": 3961, "departure": { "airport": "DEL", "city": "DEL", "country": "IN", "time": "02:10:00+05:30", "terminal": "3" }, "arrival": { "airport": "AMS", "city": "AMS", "country": "NL", "time": "07:40:00+02:00" }, "carrier": { "marketing": "KL", "marketingFlightNumber": 3817, "operating": "9W", "operatingFlightNumber": 234, "disclosure": "9W", "equipment": { "code": "333", "typeForFirstLeg": "W", "typeForLastLeg": "W" } } }, { "id": 5, "frequency": "*MTWTFS", "stopCount": 0, "eTicketable": true, "totalMilesFlown": 257, "departure": { "airport": "AMS", "city": "AMS", "country": "NL", "time": "09:25:00+02:00" }, "arrival": { "airport": "LCY", "city": "LON", "country": "GB", "time": "09:30:00+01:00" }, "carrier": { "marketing": "KL", "marketingFlightNumber": 987, "operating": "KL", "operatingFlightNumber": 987, "codeShared": "/KLM CITYHOPPER", "equipment": { "code": "E90", "typeForFirstLeg": "N", "typeForLastLeg": "N" } } } ], "taxDescs": [ { "id": 1, "code": "YRI", "amount": 160, "currency": "USD", "description": "SERVICE FEE - CARRIER-IMPOSED MISC", "publishedAmount": 160, "publishedCurrency": "USD", "station": "DEL" }, { "id": 2, "code": "YQI", "amount": 13.3, "currency": "USD", "description": "SERVICE FEE - INSURANCE", "publishedAmount": 925, "publishedCurrency": "INR", "station": "BLR" }, { "id": 3, "code": "WO", "amount": 3.8, "currency": "USD", "description": "PASSENGER SERVICE FEE", "publishedAmount": 3.8, "publishedCurrency": "USD", "station": "BLR", "country": "IN" }, { "id": 4, "code": "K38", "amount": 11.5, "currency": "USD", "description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL", "publishedAmount": 799, "publishedCurrency": "INR", "station": "BLR", "country": "IN" }, { "id": 5, "code": "CJ", "amount": 7.4, "currency": "USD", "description": "SECURITY SERVICE CHARGE", "publishedAmount": 6.5, "publishedCurrency": "EUR", "station": "AMS", "country": "NL" }, { "id": 6, "code": "RN", "amount": 7.3, "currency": "USD", "description": "PASSENGER SERVICE CHARGE", "publishedAmount": 6.4, "publishedCurrency": "EUR", "station": "AMS", "country": "NL" }, { "id": 7, "code": "IN", "amount": 5.2, "currency": "USD", "description": "USER DEVELOPMENT FEE DEPARTURES", "publishedAmount": 362, "publishedCurrency": "INR", "station": "BLR", "country": "IN" } ], "taxSummaryDescs": [ { "id": 1, "code": "YRI", "amount": 160, "currency": "USD", "description": "SERVICE FEE - CARRIER-IMPOSED MISC", "publishedAmount": 160, "publishedCurrency": "USD", "station": "DEL" }, { "id": 2, "code": "YQI", "amount": 13.3, "currency": "USD", "description": "SERVICE FEE - INSURANCE", "publishedAmount": 925, "publishedCurrency": "INR", "station": "BLR" }, { "id": 3, "code": "WO", "amount": 3.8, "currency": "USD", "description": "PASSENGER SERVICE FEE", "publishedAmount": 3.8, "publishedCurrency": "USD", "station": "BLR", "country": "IN" }, { "id": 4, "code": "K38", "amount": 11.5, "currency": "USD", "description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL", "publishedAmount": 0.05, "publishedCurrency": "INR", "station": "BLR", "country": "IN" }, { "id": 5, "code": "CJ", "amount": 7.4, "currency": "USD", "description": "SECURITY SERVICE CHARGE", "publishedAmount": 6.5, "publishedCurrency": "EUR", "station": "AMS", "country": "NL" }, { "id": 6, "code": "RN", "amount": 7.3, "currency": "USD", "description": "PASSENGER SERVICE CHARGE", "publishedAmount": 6.4, "publishedCurrency": "EUR", "station": "AMS", "country": "NL" }, { "id": 7, "code": "IN", "amount": 5.2, "currency": "USD", "description": "USER DEVELOPMENT FEE DEPARTURES", "publishedAmount": 362, "publishedCurrency": "INR", "station": "BLR", "country": "IN" } ], "fareComponentDescs": [ { "id": 1, "governingCarrier": "KL", "fareAmount": 24.65, "fareCurrency": "INR", "fareBasisCode": "XPLWIA", "farePassengerType": "ADT", "publishedFareAmount": 1717, "oneWayFare": true, "directionality": "FROM", "direction": "EH", "notValidBefore": "2019-07-21", "notValidAfter": "2019-07-21", "applicablePricingCategories": "4 5 6 7 8 10 12 16 18", "vendorCode": "ATP", "fareTypeBitmap": "00", "fareType": "PRU", "fareTariff": "4", "fareRule": "INPL", "segments": [ { "segment": { "surcharges": [ { "amount": 28.71, "currency": "NUC", "description": "MISCELLANEOUS/OTHER", "type": "Q" } ] } }, { "segment": {} }, { "segment": {} } ] } ], "validatingCarrierDescs": [ { "id": 1, "settlementMethod": "ARC", "newVcxProcess": true, "default": { "code": "DL" } } ], "baggageAllowanceDescs": [ { "id": 1, "pieceCount": 1 } ], "legDescs": [ { "id": 1, "schedules": [ { "ref": 2 }, { "ref": 4, "departureDateAdjustment": 1 }, { "ref": 5, "departureDateAdjustment": 1 } ] }, { "id": 2, "schedules": [ { "ref": 3 }, { "ref": 4, "departureDateAdjustment": 1 }, { "ref": 1, "departureDateAdjustment": 1 } ] } ], "itineraryGroups": [ { "groupDescription": { "legDescriptions": [ { "departureDate": "2019-07-21", "departureLocation": "BLR", "arrivalLocation": "LCY" } ] }, "itineraries": [ { "id": 1, "pricingSource": "ADVJR1", "legs": [ { "ref": 2 } ], "pricingInformation": [ { "pricingSubsource": "MIP", "fare": { "validatingCarrierCode": "DL", "vita": true, "eTicketable": true, "lastTicketDate": "2019-07-05", "governingCarriers": "KL", "passengerInfoList": [ { "passengerInfo": { "passengerType": "ADT", "passengerNumber": 1, "nonRefundable": true, "fareComponents": [ { "ref": 1, "segments": [ { "segment": { "bookingCode": "X", "cabinCode": "Y", "mealCode": "D", "seatsAvailable": 9 } }, { "segment": { "bookingCode": "X", "cabinCode": "Y", "mealCode": "RB", "seatsAvailable": 9 } }, { "segment": { "bookingCode": "L", "cabinCode": "Y", "mealCode": "M", "seatsAvailable": 9, "availabilityBreak": true } } ] } ], "taxes": [ { "ref": 2 }, { "ref": 1 }, { "ref": 7 }, { "ref": 4 }, { "ref": 3 }, { "ref": 5 }, { "ref": 6 } ], "taxSummaries": [ { "ref": 2 }, { "ref": 1 }, { "ref": 3 }, { "ref": 4 }, { "ref": 7 }, { "ref": 5 }, { "ref": 6 } ], "currencyConversion": { "from": "INR", "to": "USD", "exchangeRateUsed": 0.01442679 }, "fareMessages": [ { "type": "N", "code": "0", "carrier": "KL", "info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY" }, { "type": "W", "code": "0", "info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL" } ], "passengerTotalFare": { "totalFare": 264.5, "totalTaxAmount": 208.5, "currency": "USD", "baseFareAmount": 3875, "baseFareCurrency": "INR", "equivalentAmount": 56, "equivalentCurrency": "USD", "constructionAmount": 55.59, "constructionCurrency": "NUC", "commissionPercentage": 0, "commissionAmount": 0, "exchangeRateOne": 69.651352 }, "baggageInformation": [ { "provisionType": "A", "airlineCode": "KL", "segments": [ { "id": 0 }, { "id": 1 }, { "id": 2 } ], "allowance": { "ref": 1 } } ] } } ], "totalFare": { "totalPrice": 264.5, "totalTaxAmount": 208.5, "currency": "USD", "baseFareAmount": 3875, "baseFareCurrency": "INR", "constructionAmount": 55.59, "constructionCurrency": "NUC", "equivalentAmount": 56, "equivalentCurrency": "USD" }, "validatingCarriers": [ { "ref": 1 } ] } } ], "diversitySwapper": { "weighedPrice": 409.855 } }, { "id": 2, "pricingSource": "ADVJR1", "legs": [ { "ref": 1 } ], "pricingInformation": [ { "pricingSubsource": "MIP", "fare": { "validatingCarrierCode": "DL", "vita": true, "eTicketable": true, "lastTicketDate": "2019-07-05", "governingCarriers": "KL", "passengerInfoList": [ { "passengerInfo": { "passengerType": "ADT", "passengerNumber": 1, "nonRefundable": true, "fareComponents": [ { "ref": 1, "segments": [ { "segment": { "bookingCode": "X", "cabinCode": "Y", "mealCode": "D", "seatsAvailable": 9 } }, { "segment": { "bookingCode": "X", "cabinCode": "Y", "mealCode": "RB", "seatsAvailable": 9 } }, { "segment": { "bookingCode": "L", "cabinCode": "Y", "mealCode": "M", "seatsAvailable": 9, "availabilityBreak": true } } ] } ], "taxes": [ { "ref": 2 }, { "ref": 1 }, { "ref": 7 }, { "ref": 4 }, { "ref": 3 }, { "ref": 5 }, { "ref": 6 } ], "taxSummaries": [ { "ref": 2 }, { "ref": 1 }, { "ref": 3 }, { "ref": 4 }, { "ref": 7 }, { "ref": 5 }, { "ref": 6 } ], "currencyConversion": { "from": "INR", "to": "USD", "exchangeRateUsed": 0.01442679 }, "fareMessages": [ { "type": "N", "code": "0", "carrier": "KL", "info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY" }, { "type": "W", "code": "0", "info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL" } ], "passengerTotalFare": { "totalFare": 264.5, "totalTaxAmount": 208.5, "currency": "USD", "baseFareAmount": 3875, "baseFareCurrency": "INR", "equivalentAmount": 56, "equivalentCurrency": "USD", "constructionAmount": 55.59, "constructionCurrency": "NUC", "commissionPercentage": 0, "commissionAmount": 0, "exchangeRateOne": 69.651352 }, "baggageInformation": [ { "provisionType": "A", "airlineCode": "KL", "segments": [ { "id": 0 }, { "id": 1 }, { "id": 2 } ], "allowance": { "ref": 1 } } ] } } ], "totalFare": { "totalPrice": 264.5, "totalTaxAmount": 208.5, "currency": "USD", "baseFareAmount": 3875, "baseFareCurrency": "INR", "constructionAmount": 55.59, "constructionCurrency": "NUC", "equivalentAmount": 56, "equivalentCurrency": "USD" }, "validatingCarriers": [ { "ref": 1 } ] } } ], "diversitySwapper": { "weighedPrice": 367.631 } } ] } ] } }
You have to use legDescs list to connect your segments, and use those "ref" values. For example: { "id": 2, "schedules": [ { "ref": 3 }, { "departureDateAdjustment": 1, "ref": 4 }, { "departureDateAdjustment": 1, "ref": 1 } ] } means, your flight with ID = 2 contains 3 segments, with id 3 - 4 and 1. When you search numbered segments in "scheduleDescs" object, you can see routes are: BLR - DEL DEL - AMS AMS - LCY and as you can see you got the BLR - LCY flight.
How do I access the name of the city nested in this api response?
I request data with axios.get(...), successful get the return as nested objects. I can access the data.message, data.cnt, data.cod but I can't access the properties of the "city". kept getting undefine or typeerror. I want to access the properties of the city object nested within the response data. like this "data.city.name" but errors. { "cod": "200", "message": 0.0051, "cnt": 40, "list": [ { "dt": 1545318000, "main": { "temp": 282.74, "temp_min": 282.167, "temp_max": 282.74, "pressure": 1012.86, "sea_level": 1020.54, "grnd_level": 1012.86, "humidity": 84, "temp_kf": 0.57 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10d" } ], "clouds": { "all": 44 }, "wind": { "speed": 5.67, "deg": 243.503 }, "rain": { "3h": 0.25 }, "sys": { "pod": "d" }, "dt_txt": "2018-12-20 15:00:00" }, { "dt": 1545739200, "main": { "temp": 282.628, "temp_min": 282.628, "temp_max": 282.628, "pressure": 1037.58, "sea_level": 1045.29, "grnd_level": 1037.58, "humidity": 100, "temp_kf": 0 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10d" } ], "clouds": { "all": 76 }, "wind": { "speed": 2.02, "deg": 212.503 }, "rain": { "3h": 0.13 }, "sys": { "pod": "d" }, "dt_txt": "2018-12-25 12:00:00" } ], "city": { "id": 2643743, "name": "London", "coord": { "lat": 51.5073, "lon": -0.1277 }, "country": "GB", "population": 1000000 } }
Use JSON.parse(); Example: var data = JSON.parse(yourJSONObject) console.log(data.city.name)
May not full represent what you need, but this should show how to set a default state, fetch your results, and then pass them into components. Your object is fine, I feel like you might be trying to access it before Axios completes. export class DataView extends Component { constructor(props) { super(props); this.state = { isLoading: true, data: {} }; this.defaultState = { // default properties of state }; } componentWillMount() { this.fetchData(); } fetchData = () => { await axios.get( ${apiEndpoint}${inputCity}&appid=${apiKey} ) .then( data => { this.setState({ data, ...this.defaultState, isLoading: false }); }); }; render() { return ( <Fragment> {this.state.isLoading ? ( // Check if it's still loading and load nothing if true <Fragment /> ) : ( <Component withProps={this.state.data}></Component> // Data can be accessed if isLoading: false )} </Fragment> ); } }
if you are getting data.message, then you must get the city name with data.city.name
I think you have some errors in your code because i can access the data and the json is also valid too. try to console.log() the response and see what's going on.
Seems to work fine with data.city.name const data = { "cod": "200", "message": 0.0051, "cnt": 40, "list": [ { "dt": 1545318000, "main": { "temp": 282.74, "temp_min": 282.167, "temp_max": 282.74, "pressure": 1012.86, "sea_level": 1020.54, "grnd_level": 1012.86, "humidity": 84, "temp_kf": 0.57 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10d" } ], "clouds": { "all": 44 }, "wind": { "speed": 5.67, "deg": 243.503 }, "rain": { "3h": 0.25 }, "sys": { "pod": "d" }, "dt_txt": "2018-12-20 15:00:00" }, { "dt": 1545739200, "main": { "temp": 282.628, "temp_min": 282.628, "temp_max": 282.628, "pressure": 1037.58, "sea_level": 1045.29, "grnd_level": 1037.58, "humidity": 100, "temp_kf": 0 }, "weather": [ { "id": 500, "main": "Rain", "description": "light rain", "icon": "10d" } ], "clouds": { "all": 76 }, "wind": { "speed": 2.02, "deg": 212.503 }, "rain": { "3h": 0.13 }, "sys": { "pod": "d" }, "dt_txt": "2018-12-25 12:00:00" } ], "city": { "id": 2643743, "name": "London", "coord": { "lat": 51.5073, "lon": -0.1277 }, "country": "GB", "population": 1000000 } } document.write(data.city.name); getData = async () => { const { inputCity } = this.state; try { const data = await axios.get(${apiEndpoint}${inputCity}&appid=${apiKey}); this.setState({ data }); console.log(this.state.data); return data; } catch (err) { console.error(err); } }
Node-RED not able to access to array member
I'm trying to access to a JSON array returned by a OpenWeatherMap request. The JSON data is: { "city": { "id": 3171457, "name": "New York", "coord": { "lon": 0.32898, "lat": 4.802662 }, "country": "US", "population": 0, "sys": { "population": 0 } }, "cod": "200", "message": 0.0317, "cnt": 40, "list": [ { "dt": 1483552800, "main": { "temp": 277.28, "temp_min": 275.705, "temp_max": 277.28, "pressure": 1013.85, "sea_level": 1021.42, "grnd_level": 1013.85, "humidity": 93, "temp_kf": 1.57 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01n" } ], "clouds": { "all": 0 }, "wind": { "speed": 4.74, "deg": 269.002 }, "sys": { "pod": "n" }, "dt_txt": "2017-01-04 18:00:00" }, ... If i use in a template {{payload.list}} I see a list of [object Object]s. But if I use {{payload.list[0]}}, or {{payload.list[0].main}}, I see nothing - my guess was a single [object Object]. How can i access to the first member and inner members?
The template node uses the mustache format, documented here: https://mustache.github.io/mustache.5.html To access array values, you should use the following syntax: {{ payload.list.0 }} and {{ payload.list.0.main }}