如何使用JavaScript从网站获取价值

时间:2019-03-10 03:55:21

标签: javascript node.js

有问题的网站就是peakspeak。我正在尝试使用Amazon Alexa来获取房间的温度。我将数据发送到Thingspeak,网站显示了这个{"created_at":"2019-03-09T05:21:52Z","entry_id":185,"field1":"21.00"},我想从网站21.00中获取价值。这是我的代码:

    var channel_id = 123456;
    var speak_key = 'ABCD2456ABCD2456';
    var url = 'https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + speak_key;
    const MyRoomHandler = {
      canHandle(handlerInput) {
        const request = handlerInput.requestEnvelope.request;
        return request.type === 'LaunchRequest'
          || (request.type === 'IntentRequest'
            && request.intent.name === 'MyRoomIntent');  
      },
      handle(handlerInput) {
        const lastTemp;         
        const speechOutput = GET_MESSAGE + lastTemp + TEMP_DEGREES;

        return handlerInput.responseBuilder
          .speak(speechOutput)
          .getResponse();
      },
    };
const SKILL_NAME = 'My Room';
const GET_MESSAGE = 'The temperature is ';
const TEMP_DEGREES = ' Degrees Celsius.';
const HELP_MESSAGE = 'You can say tell me to get the temperature, or you can say exit... What can I help you with?';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Goodbye!';

我只是不知道如何使变量lastTemp从网站上获得该值21.00。我不懂JavaScript。我现在将开始为将来的项目学习它,只需要弄清楚这部分。谢谢您的帮助。

0 个答案:

没有答案