我正在编写一个代码,我需要从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