前提・実現したいこと
こんにちは。
Raspberry Pi Zero WでNodejsとnpmとOpenWeatherMapを用いて天気の予測プログラムを書いていたのですが、いざ実行しようとすると以下のエラーが出てしまいました。
色々検索して見たのですが初心者なのでよくわかりませんでした。。。
よろしくお願いします。
発生している問題・エラーメッセージ
undefined:1
undefined
^
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at Request._callback (/home/pi/node_modules/npm-openweathermap/lib/weather.js:51:15)
at self.callback (/home/pi/node_modules/request/request.js:185:22)
at Request.emit (events.js:182:13)
at Request.onRequestError (/home/pi/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:182:13)
at Socket.socketErrorListener (_http_client.js:391:9)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
該当のソースコード
var weather = require('npm-openweathermap'); //ライブラリを持ってくる
weather.api_key = '取得APIキー'; //自分で取得したAPIキーを入力
weather.get_weather_custom('city','Tokyo','forecast').then(function(res){ //get_weather_customで東京の天気をとってくる。resの中に5日分の3時間ごとの天気予測
for(var I=0; I<7; I++){
var weather = res[I].weather[0];
console.log(weather.id); //天気の表示
}
},function(error){
console.log(error)
})
試したこと
他の解決策のサイトを拝見し他のですがよくわからず、エラー発生の分の直前にconsole.log()を書くといいという答えがあったので試しましたがダメでした。
回答1件
あなたの回答
tips
プレビュー