我是JSON的新手,我正在处理的文件在对象中有很多对象(它们都是不同的变量类型,例如String,Int,Boolean)。我正在尝试创建一个天气预报程序。我已经尝试将其转换为csv并尝试从JSON数组中取出值但不幸的是我遇到了所有不同变量类型的麻烦。任何帮助将不胜感激。我已粘贴下面的JSON内容:
{
"cod": "200",
"message": 0.0029,
"cnt": 40,
"list": [{
"dt": 1517173200,
"main": {
"temp": 282.57,
"temp_min": 282.104,
"temp_max": 282.57,
"pressure": 1033.47,
"sea_level": 1043.6,
"grnd_level": 1033.47,
"humidity": 88,
"temp_kf": 0.47
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 64
},
"wind": {
"speed": 7.12,
"deg": 246.005
},
"rain": {
"3h": 0.015
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-28 21:00:00"
}, {
"dt": 1517184000,
"main": {
"temp": 282.21,
"temp_min": 281.86,
"temp_max": 282.21,
"pressure": 1032.19,
"sea_level": 1042.34,
"grnd_level": 1032.19,
"humidity": 89,
"temp_kf": 0.35
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 88
},
"wind": {
"speed": 8.31,
"deg": 246.502
},
"rain": {
"3h": 0.065
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-29 00:00:00"
}, {
"dt": 1517194800,
"main": {
"temp": 282.23,
"temp_min": 281.993,
"temp_max": 282.23,
"pressure": 1030.92,
"sea_level": 1041.15,
"grnd_level": 1030.92,
"humidity": 88,
"temp_kf": 0.24
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 76
},
"wind": {
"speed": 9.05,
"deg": 248.007
},
"rain": {
"3h": 0.1
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-29 03:00:00"
}, {
"dt": 1517205600,
"main": {
"temp": 282.83,
"temp_min": 282.712,
"temp_max": 282.83,
"pressure": 1029.66,
"sea_level": 1039.73,
"grnd_level": 1029.66,
"humidity": 87,
"temp_kf": 0.12
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 9.23,
"deg": 249.501
},
"rain": {
"3h": 0.13
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-29 06:00:00"
}, {
"dt": 1517216400,
"main": {
"temp": 283.386,
"temp_min": 283.386,
"temp_max": 283.386,
"pressure": 1028.77,
"sea_level": 1038.91,
"grnd_level": 1028.77,
"humidity": 87,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 9.1,
"deg": 250.003
},
"rain": {
"3h": 0.15
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-29 09:00:00"
}, {
"dt": 1517227200,
"main": {
"temp": 284.502,
"temp_min": 284.502,
"temp_max": 284.502,
"pressure": 1027.71,
"sea_level": 1037.77,
"grnd_level": 1027.71,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 9.17,
"deg": 248.004
},
"rain": {
"3h": 0.57
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-29 12:00:00"
}, {
"dt": 1517238000,
"main": {
"temp": 282.125,
"temp_min": 282.125,
"temp_max": 282.125,
"pressure": 1029.47,
"sea_level": 1039.55,
"grnd_level": 1029.47,
"humidity": 100,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 7.21,
"deg": 323.003
},
"rain": {
"3h": 1.865
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-29 15:00:00"
}, {
"dt": 1517248800,
"main": {
"temp": 278.662,
"temp_min": 278.662,
"temp_max": 278.662,
"pressure": 1032.69,
"sea_level": 1042.99,
"grnd_level": 1032.69,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 4.47,
"deg": 314.005
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-29 18:00:00"
}, {
"dt": 1517259600,
"main": {
"temp": 276.508,
"temp_min": 276.508,
"temp_max": 276.508,
"pressure": 1035.09,
"sea_level": 1045.44,
"grnd_level": 1035.09,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 3.42,
"deg": 293.004
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-29 21:00:00"
}, {
"dt": 1517270400,
"main": {
"temp": 274.987,
"temp_min": 274.987,
"temp_max": 274.987,
"pressure": 1035.85,
"sea_level": 1046.28,
"grnd_level": 1035.85,
"humidity": 93,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 3.23,
"deg": 285.002
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-30 00:00:00"
}, {
"dt": 1517281200,
"main": {
"temp": 273.6,
"temp_min": 273.6,
"temp_max": 273.6,
"pressure": 1035.63,
"sea_level": 1046.13,
"grnd_level": 1035.63,
"humidity": 89,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 2.07,
"deg": 250.502
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-30 03:00:00"
}, {
"dt": 1517292000,
"main": {
"temp": 273.127,
"temp_min": 273.127,
"temp_max": 273.127,
"pressure": 1035.12,
"sea_level": 1045.78,
"grnd_level": 1035.12,
"humidity": 90,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 2.73,
"deg": 244.001
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-30 06:00:00"
}, {
"dt": 1517302800,
"main": {
"temp": 273.276,
"temp_min": 273.276,
"temp_max": 273.276,
"pressure": 1034.91,
"sea_level": 1045.49,
"grnd_level": 1034.91,
"humidity": 86,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "02d"
}],
"clouds": {
"all": 8
},
"wind": {
"speed": 1.73,
"deg": 206.501
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-30 09:00:00"
}, {
"dt": 1517313600,
"main": {
"temp": 279.265,
"temp_min": 279.265,
"temp_max": 279.265,
"pressure": 1033.09,
"sea_level": 1043.32,
"grnd_level": 1033.09,
"humidity": 100,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 2.59,
"deg": 207.001
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-30 12:00:00"
}, {
"dt": 1517324400,
"main": {
"temp": 279.913,
"temp_min": 279.913,
"temp_max": 279.913,
"pressure": 1029.52,
"sea_level": 1039.73,
"grnd_level": 1029.52,
"humidity": 90,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 4.32,
"deg": 213.507
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-30 15:00:00"
}, {
"dt": 1517335200,
"main": {
"temp": 277.804,
"temp_min": 277.804,
"temp_max": 277.804,
"pressure": 1026.44,
"sea_level": 1036.74,
"grnd_level": 1026.44,
"humidity": 87,
"temp_kf": 0
},
"weather": [{
"id": 802,
"main": "Clouds",
"description": "scattered clouds",
"icon": "03n"
}],
"clouds": {
"all": 44
},
"wind": {
"speed": 4.85,
"deg": 199.001
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-30 18:00:00"
}, {
"dt": 1517346000,
"main": {
"temp": 278.566,
"temp_min": 278.566,
"temp_max": 278.566,
"pressure": 1021.17,
"sea_level": 1031.32,
"grnd_level": 1021.17,
"humidity": 96,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 6.36,
"deg": 191.003
},
"rain": {
"3h": 0.66
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-30 21:00:00"
}, {
"dt": 1517356800,
"main": {
"temp": 282.617,
"temp_min": 282.617,
"temp_max": 282.617,
"pressure": 1016,
"sea_level": 1026.08,
"grnd_level": 1016,
"humidity": 95,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 8.51,
"deg": 237.501
},
"rain": {
"3h": 2.06
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-31 00:00:00"
}, {
"dt": 1517367600,
"main": {
"temp": 281.237,
"temp_min": 281.237,
"temp_max": 281.237,
"pressure": 1013.75,
"sea_level": 1023.88,
"grnd_level": 1013.75,
"humidity": 96,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 9.06,
"deg": 256.001
},
"rain": {
"3h": 0.62
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-31 03:00:00"
}, {
"dt": 1517378400,
"main": {
"temp": 281.267,
"temp_min": 281.267,
"temp_max": 281.267,
"pressure": 1011.51,
"sea_level": 1021.54,
"grnd_level": 1011.51,
"humidity": 95,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 88
},
"wind": {
"speed": 9.33,
"deg": 257.505
},
"rain": {
"3h": 0.5
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-31 06:00:00"
}, {
"dt": 1517389200,
"main": {
"temp": 279.674,
"temp_min": 279.674,
"temp_max": 279.674,
"pressure": 1011.09,
"sea_level": 1021.14,
"grnd_level": 1011.09,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 24
},
"wind": {
"speed": 9.3,
"deg": 263.503
},
"rain": {
"3h": 0.04
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-31 09:00:00"
}, {
"dt": 1517400000,
"main": {
"temp": 279.173,
"temp_min": 279.173,
"temp_max": 279.173,
"pressure": 1010.11,
"sea_level": 1020.08,
"grnd_level": 1010.11,
"humidity": 96,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 80
},
"wind": {
"speed": 8.26,
"deg": 272.001
},
"rain": {
"3h": 1.34
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-31 12:00:00"
}, {
"dt": 1517410800,
"main": {
"temp": 279.275,
"temp_min": 279.275,
"temp_max": 279.275,
"pressure": 1008.09,
"sea_level": 1018.11,
"grnd_level": 1008.09,
"humidity": 94,
"temp_kf": 0
},
"weather": [{
"id": 802,
"main": "Clouds",
"description": "scattered clouds",
"icon": "03d"
}],
"clouds": {
"all": 48
},
"wind": {
"speed": 8.01,
"deg": 270
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-01-31 15:00:00"
}, {
"dt": 1517421600,
"main": {
"temp": 277.443,
"temp_min": 277.443,
"temp_max": 277.443,
"pressure": 1006.4,
"sea_level": 1016.46,
"grnd_level": 1006.4,
"humidity": 87,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 7.01,
"deg": 264.501
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-31 18:00:00"
}, {
"dt": 1517432400,
"main": {
"temp": 277.065,
"temp_min": 277.065,
"temp_max": 277.065,
"pressure": 1004.03,
"sea_level": 1014.1,
"grnd_level": 1004.03,
"humidity": 85,
"temp_kf": 0
},
"weather": [{
"id": 802,
"main": "Clouds",
"description": "scattered clouds",
"icon": "03n"
}],
"clouds": {
"all": 32
},
"wind": {
"speed": 7.98,
"deg": 251.501
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-01-31 21:00:00"
}, {
"dt": 1517443200,
"main": {
"temp": 277.557,
"temp_min": 277.557,
"temp_max": 277.557,
"pressure": 1001.39,
"sea_level": 1011.39,
"grnd_level": 1001.39,
"humidity": 86,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 64
},
"wind": {
"speed": 7.96,
"deg": 258.501
},
"rain": {
"3h": 0.02
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-01 00:00:00"
}, {
"dt": 1517454000,
"main": {
"temp": 277.952,
"temp_min": 277.952,
"temp_max": 277.952,
"pressure": 997.38,
"sea_level": 1007.44,
"grnd_level": 997.38,
"humidity": 85,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 68
},
"wind": {
"speed": 9.4,
"deg": 253.001
},
"rain": {
"3h": 0.02
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-01 03:00:00"
}, {
"dt": 1517464800,
"main": {
"temp": 277.626,
"temp_min": 277.626,
"temp_max": 277.626,
"pressure": 994.99,
"sea_level": 1005.22,
"grnd_level": 994.99,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 8.16,
"deg": 290.5
},
"rain": {
"3h": 0.54
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-01 06:00:00"
}, {
"dt": 1517475600,
"main": {
"temp": 276.999,
"temp_min": 276.999,
"temp_max": 276.999,
"pressure": 1000.97,
"sea_level": 1011.14,
"grnd_level": 1000.97,
"humidity": 95,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 11.51,
"deg": 357.005
},
"rain": {
"3h": 1.51
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-01 09:00:00"
}, {
"dt": 1517486400,
"main": {
"temp": 277.994,
"temp_min": 277.994,
"temp_max": 277.994,
"pressure": 1006.61,
"sea_level": 1016.71,
"grnd_level": 1006.61,
"humidity": 93,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 36
},
"wind": {
"speed": 9.61,
"deg": 344.501
},
"rain": {
"3h": 0.059999999999999
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-01 12:00:00"
}, {
"dt": 1517497200,
"main": {
"temp": 278.503,
"temp_min": 278.503,
"temp_max": 278.503,
"pressure": 1008.13,
"sea_level": 1018.32,
"grnd_level": 1008.13,
"humidity": 86,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 76
},
"wind": {
"speed": 7.56,
"deg": 335.5
},
"rain": {
"3h": 0.0099999999999998
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-01 15:00:00"
}, {
"dt": 1517508000,
"main": {
"temp": 278.147,
"temp_min": 278.147,
"temp_max": 278.147,
"pressure": 1011.25,
"sea_level": 1021.29,
"grnd_level": 1011.25,
"humidity": 85,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 56
},
"wind": {
"speed": 7.51,
"deg": 356.505
},
"rain": {
"3h": 0.22
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-01 18:00:00"
}, {
"dt": 1517518800,
"main": {
"temp": 277.529,
"temp_min": 277.529,
"temp_max": 277.529,
"pressure": 1014.07,
"sea_level": 1024.28,
"grnd_level": 1014.07,
"humidity": 87,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 92
},
"wind": {
"speed": 7.26,
"deg": 350.501
},
"rain": {
"3h": 0.23
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-01 21:00:00"
}, {
"dt": 1517529600,
"main": {
"temp": 277.027,
"temp_min": 277.027,
"temp_max": 277.027,
"pressure": 1016.85,
"sea_level": 1027.01,
"grnd_level": 1016.85,
"humidity": 85,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 20
},
"wind": {
"speed": 7.16,
"deg": 0.00292969
},
"rain": {
"3h": 0.07
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-02 00:00:00"
}, {
"dt": 1517540400,
"main": {
"temp": 275.98,
"temp_min": 275.98,
"temp_max": 275.98,
"pressure": 1019.25,
"sea_level": 1029.5,
"grnd_level": 1019.25,
"humidity": 83,
"temp_kf": 0
},
"weather": [{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02n"
}],
"clouds": {
"all": 12
},
"wind": {
"speed": 6.55,
"deg": 1.5011
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-02 03:00:00"
}, {
"dt": 1517551200,
"main": {
"temp": 275.064,
"temp_min": 275.064,
"temp_max": 275.064,
"pressure": 1021.34,
"sea_level": 1031.64,
"grnd_level": 1021.34,
"humidity": 84,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "02n"
}],
"clouds": {
"all": 8
},
"wind": {
"speed": 5.11,
"deg": 1.00006
},
"rain": {},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-02 06:00:00"
}, {
"dt": 1517562000,
"main": {
"temp": 274.354,
"temp_min": 274.354,
"temp_max": 274.354,
"pressure": 1023.32,
"sea_level": 1033.73,
"grnd_level": 1023.32,
"humidity": 91,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"clouds": {
"all": 0
},
"wind": {
"speed": 3.76,
"deg": 355.502
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-02 09:00:00"
}, {
"dt": 1517572800,
"main": {
"temp": 278.331,
"temp_min": 278.331,
"temp_max": 278.331,
"pressure": 1024.86,
"sea_level": 1035.07,
"grnd_level": 1024.86,
"humidity": 93,
"temp_kf": 0
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "02d"
}],
"clouds": {
"all": 8
},
"wind": {
"speed": 3.56,
"deg": 351.002
},
"rain": {},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-02 12:00:00"
}, {
"dt": 1517583600,
"main": {
"temp": 279.161,
"temp_min": 279.161,
"temp_max": 279.161,
"pressure": 1024.46,
"sea_level": 1034.7,
"grnd_level": 1024.46,
"humidity": 86,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"clouds": {
"all": 56
},
"wind": {
"speed": 2.56,
"deg": 338.001
},
"rain": {
"3h": 0.02
},
"sys": {
"pod": "d"
},
"dt_txt": "2018-02-02 15:00:00"
}, {
"dt": 1517594400,
"main": {
"temp": 277.055,
"temp_min": 277.055,
"temp_max": 277.055,
"pressure": 1025.12,
"sea_level": 1035.4,
"grnd_level": 1025.12,
"humidity": 85,
"temp_kf": 0
},
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10n"
}],
"clouds": {
"all": 44
},
"wind": {
"speed": 1.66,
"deg": 294.004
},
"rain": {
"3h": 0.029999999999999
},
"sys": {
"pod": "n"
},
"dt_txt": "2018-02-02 18:00:00"
}],
"city": {
"id": 2633709,
"name": "Woking",
"coord": {
"lat": 51.319,
"lon": -0.559
},
"country": "GB"
}
}
答案 0 :(得分:1)
你需要从对象的角度思考。你最外层的Object是某种包装器,它包含大多数其他重要的对象。
我试图将JSON转换为适当的对象结构。我希望你明白我的观点。请添加缺少的对象。
open_graph_story
正如您所看到的,我有一个public class OuterMainObject {
private String cod;
private float message;
private int cnt;
List<WeatherObject> list = new ArrayList<WeatherObject>();
private City city;
}
class City {
private String id;
private String name;
private Coordinates coord;
private String country;
}
class Coordinates {
private double lat;
private double lon;
}
class WeatherObject {
private Date dt;
private Main main;
private Weather weather;
private Clouds clouds;
private Wind wind;
private Rain rain;
private Sys sys;
private String dt_txt;
}
并且OuterMainObject
中有多个对象,如果您尝试将对象从外部映射到内部,则可以轻松地将它们关联起来。
评论更新 我们不必担心如何检测和存储变量。有些图书馆为我们这样做。所以杰克逊就是这样的图书馆之一。请参阅此link。这个有关于这种转换的很好的教程。您需要关注的只是将JSON转换为适当的对象结构。
在你的情况下,应该这样做。
outermainobject
答案 1 :(得分:0)
尝试这样.....
JSONObject JOBJ= new JSONObject(response);
JSONArray JS= JOBJ.getJSONArray("list");
for (int i = 0; i < JS.length(); i++) {
JSONObject c = JS.getJSONObject(i);
JSONObject main= paramsArr.getJSONObject("main");
System.out.println(main.getString("temp"));
//like this...
JSONArray JS2= JOBJ.getJSONArray("weather");
for (int j = 0; j < JS2.length(); j++)
{
JSONObject param1 = JS2.getJSONObject(0);
//now get required values by key
System.out.println(param1.getInt("id"));
}
}