我有困难的时间遍历这个数据集从ajax调用拉到天气api。我想获取诸如temp或id之类的东西的值,但不断收到错误。我试过这个weather.weather ['id'],weather.weather.id,weather.weather [0]。我知道最高的天气层是一个物体。但第二个天气传递数组?那有一个对象?我如何从这里获取信息?对于正常的数据集我有一些想法,但这对我来说太奇怪了。注:这是VUEJSAjax数据对象意外行为
AJAX调用:
$.getJSON('http://api.openweathermap.org/data/2.5/weather?id=6356055&appid=44db6a862fba0b067b1930da0d769e98', function(weather) {
this.weather_data = weather;
}.bind(this));
这是穿我的数据推到我的空数组
weather_data: [],
那么现在我只是在努力确保其内的一些工作这样的标签:
{{ weather_data.weather[0].id | json}}
这里是从getjson调用中拉回来的东西。
"weather": {
"coord": {
"lon": 2.13,
"lat": 41.4
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "cmc stations",
"main": {
"temp": 285.622,
"pressure": 1006.71,
"humidity": 98,
"temp_min": 285.622,
"temp_max": 285.622,
"sea_level": 1015.25,
"grnd_level": 1006.71
},
"wind": {
"speed": 2.61,
"deg": 267.501
},
"clouds": {
"all": 0
},
"dt": 1457178093,
"sys": {
"message": 0.0042,
"country": "ES",
"sunrise": 1457158704,
"sunset": 1457200063
},
"id": 6356055,
"name": "Barcelona",
"cod": 200
},
尝试这种weather_data.weather
yeilds这个
[
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
]
https://jsfiddle.net/mca27kfr/ – Rayon
data.weather.weather [0] .id将提供结果。向我们展示如何解析和访问数据。 – Aravind
我添加了更多详细信息 –