OpenWeatherMap预测无效的JSON

时间:2017-10-31 13:14:44

标签: javascript json node.js weather-api openweathermap

当我用:

打电话给openweathermap时
http.get('http://api.openweathermap.org/data/2.5/forecast?q=Milan,it&lang=it&units=metric&APPID=*****************', res => {
        res.on('data', function (openweather) { ...

我得到一个部分字符串:

{"cod":"200","message":0.2451,"cnt":40,"list":[{"dt":1509462000,"main":{"temp":15.86,"temp_min":14.41,"temp_max":15.86,"pressure":1010.76,"sea_level":1037.47,"grnd_level":1010.76,"humidity":70,"temp_kf":1.45},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":0.24,"deg":257.001},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-10-31 15:00:00"},{"dt":1509472800,"main":{"temp":9.8,"temp_min":8.72,"temp_max":9.8,"pressure":1011.36,"sea_level":1038.47,"grnd_level":1011.36,"humidity":86,"temp_kf":1.08},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":0.46,"deg":256.507},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-10-31 18:00:00"},{"dt":1509483600,"main":{"temp":6.87,"temp_min":6.15,"temp_max":6.87,"pressure":1011.98,"sea_level":1039.25,"grnd_level":1011.98,"humidity":89,"temp_kf":0.72},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01n"}],"clouds":{
undefined:1
{"cod":"200","message":0.2451,"cnt":40,"list":[{"dt":1509462000,"main":{"temp":15.86,"temp_min":14.41,"temp_max":15.86,"pressure":1010.76,"sea_level":1037.47,"grnd_level":1010.76,"humidity":70,"temp_kf":1.45},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":0.24,"deg":257.001},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-10-31 15:00:00"},{"dt":1509472800,"main":{"temp":9.8,"temp_min":8.72,"temp_max":9.8,"pressure":1011.36,"sea_level":1038.47,"grnd_level":1011.36,"humidity":86,"temp_kf":1.08},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":0.46,"deg":256.507},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-10-31 18:00:00"},{"dt":1509483600,"main":{"temp":6.87,"temp_min":6.15,"temp_max":6.87,"pressure":1011.98,"sea_level":1039.25,"grnd_level":1011.98,"humidity":89,"temp_kf":0.72},"weather":[{"id":800,"main":"Clear","description":"cielo sereno","icon":"01n"}],"clouds":{

在使用邮递员或浏览器调用相同的URL时,我获得了有效的JSON。 同样使用一些npm模块我得到了相同的结果。

0 个答案:

没有答案