我正在編寫一個代碼,我需要從json數組中獲取具體的值。我的JSON是如下:使用jackson從json數組中檢索一個值
{
"coord": {
"lon": 68.37,
"lat": 25.39
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"base": "stations",
"main": {
"temp": 302.645,
"pressure": 1023.33,
"humidity": 48,
"temp_min": 302.645,
"temp_max": 302.645,
"sea_level": 1025.53,
"grnd_level": 1023.33
},
"wind": {
"speed": 1.81,
"deg": 54.0002
},
"clouds": {
"all": 0
},
"dt": 1479887201,
"sys": {
"message": 0.0023,
"country": "PK",
"sunrise": 1479865789,
"sunset": 1479904567
},
"id": 1176734,
"name": "Hyderabad",
"cod": 200
}
我想從天氣陣列得到ID。如果有很多,我想獲得第一個項目的ID。
請讓我知道我該怎麼做。
我使用來獲取天氣陣列的代碼是:
text = builder.toString();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = mapper.readValue(text, new TypeReference<Map<String, Object>>() {
});
List mainMap2 = (List) map.get("weather");
for (Object item : mainMap2) {
System.out.println("itemResult" + item.toString());
}
這裏,文本是JSON字符串。
,這裏是無效的JSON – peter
關注一下。[http://stackoverflow.com/questions/23499721/how-to-parse-json-array-value-using-json-node](http://stackoverflow。 COM /問題/ 23499721 /如何對解析-JSON陣列 - 值使用JSON的節點) – peter