私は学校プロジェクトに取り組んでおり、Alexaスキルとの統合のためにURLからデータを取得しようとしています。私は間違いなくNodeJSの初心者であり、HTMLまたはJSONのバックグラウンドはほとんどありません。 https://prtstatus.wvu.edu/api/ タイムスタンプ付きサンプルケースはここにある:私のコードではAmazon AlexaスキルのNodeJSの問題
https://prtstatus.wvu.edu/api/1501906657/?format=jsonが、私はJSON文字列からと解析取得しようとしている
私の学校は、ここで私たちの交通システムのための「API」を持っていますURLから取得しますが、文字列の "message:"部分が渡されるように書式設定する問題が発生しています。ここに私のAWSラムダの私の意図のためのコードは次のとおりです。コードに対処する必要があります物事のカップルがあります
'getPRTStatus': function() {
var date = Math.round(new Date().getTime()/1000);
var http = require('http');
var https = require('https');
var options = {
host: 'https://prtstatus.wvu.edu',
path: '/api/'+date+'/?format=json'
};
var object;
var callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function() {
console.log(str);
object = JSON.parse(str);
});
}
https.request(options, callback).end();
this.attributes.speechOutput = this.t(object.message);
this.attributes.repromptSpeech = this.t(object.message);
this.emit(':ask', this.attributes.speechOutput, this.attributes.repromptSpeech);
},