未知值';json';(部署JavaScript函数时)

未知值';json';(部署JavaScript函数时),javascript,firebase,google-cloud-functions,Javascript,Firebase,Google Cloud Functions,我试图部署一个Firebase函数(应用程序的通知),从第三方网站获取一个值。但是,当我调用json时,它表示错误日志中不存在该值。有没有一个明显的解决办法 后续编辑:如何获取要在标题中显示的fetch方法中的数据 const url = new URL( "test.com" ); let params = { "value": "title", }; Object.keys(params) .forEach(k

我试图部署一个Firebase函数(应用程序的通知),从第三方网站获取一个值。但是,当我调用json时,它表示错误日志中不存在该值。有没有一个明显的解决办法

后续编辑:如何获取要在标题中显示的fetch方法中的数据

 const url = new URL(
        "test.com"
    );
    let params = {
        "value": "title",
    };
    Object.keys(params)
        .forEach(key => url.searchParams.append(key, params[key]));

    fetch(url, {
        method: 'GET',
      })
      //This is where you usually would log the data .then(json => console.log(json));

      const payload = {
              notification: {
              title: json,
              body:  'The current events for today have been updated.',
              badge: '0',
              sound: 'default',
          }
      };

您应该更新
有效负载
变量。没有名为
json
的变量作为
title
的值。您的
有效负载应为

const payload = {
      notification: {
      title: 'json', // <-- mark here
      body:  'The current events for today have been updated.',
      badge: '0',
      sound: 'default',
   }
};

如果我理解您实际想要做什么,那么您缺少了
获取请求的
.then()
方法。比如:

fetch(url, {
    method: 'GET'    // You also had a wrong comma here
}).then(json => {
    // In here, json will contain the response from the fetch,
    // so you can use it however you prefer

    const payload = {
        notification: {
        title: json,
        body:  'The current events for today have been updated.',
        badge: '0',
        sound: 'default',
    }

    // do anything else

});

json
没有定义。那么从中获取json数据的正确方法是什么?我不知道。这里的用意是什么?您是否期望
json
具有一些价值?是否只传递字符串
“json”
?这是否回答了您的问题?对,但我怎么称呼它呢?这就是我的问题。史密斯说那里有什么?应该发生什么?我只希望fetch方法中的数据显示在标题中。您必须使用
。然后
异步
/
等待
执行此操作。获取错误“npm ERR!”!代码ELIFECYCLE’从这个看起来不错,但它给了我一个错误npm ERR!当我尝试部署它时,在functions@lint脚本中失败。刚刚编辑,我假设它是您代码片段中
'GET'
之后的逗号。谢谢!现在我得到了一个不同的错误:错误解析错误:意外的令牌,和npm错误!代码ELIFECYCLEWell,我只能根据经验猜测:意外的标记可能来自脚本的某个部分,试图将JSON字符串解析为对象,但实际上没有接收有效的JSON,而ELIFECYCLE几乎可以是任何东西,可能是异步方法中的非托管异常。恐怕我们从你的问题中看不出什么。
fetch(url, {
    method: 'GET'    // You also had a wrong comma here
}).then(json => {
    // In here, json will contain the response from the fetch,
    // so you can use it however you prefer

    const payload = {
        notification: {
        title: json,
        body:  'The current events for today have been updated.',
        badge: '0',
        sound: 'default',
    }

    // do anything else

});