从JavaScript中的api获取数据

时间:2018-08-24 17:24:13

标签: javascript html api web

我从API获得此信息

import

如何获得湿度? 这是我的功能不起作用:

{"coord":{"lon":26.1,"lat":44.44},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":27.98,"pressure":1011,"humidity":30,"temp_min":27,"temp_max":29},"visibility":10000,"wind":{"speed":1.5,"deg":80},"clouds":{"all":0},"dt":1535128200,"sys":{"type":1,"id":5986,"message":0.0256,"country":"RO","sunrise":1535081370,"sunset":1535130317},"id":683506,"name":"Bucharest","cod":200}

1 个答案:

答案 0 :(得分:1)

使用:

result.main.humidity;

代替:

result.weather[0].humidity;

我建议您使用https://stackoverflow.com/a/52009992/9705485使您更容易看到JSON对象的实际情况。