【问题标题】:How to return JSON Azure functio app httptrigger?如何返回 JSON Azure 函数应用 http 触发器?
【发布时间】:2020-08-18 11:59:08
【问题描述】:

我创建了带有 http 触发器的 Azure 函数应用程序,它应该返回 JSON 文件。

这是我的 nodejs 脚本的一部分。


var promise = Promise.all([getFood("first"), getFood("second"), getFood("third")]); 
promise.then(function(data) {
        let res = JSON.stringify(data);

        context.res = {
            body: res
        };
        context.done();
});

它什么也不返回。

但是当我尝试使用类似这样的脚本时,它可以工作:

var promise = Promise.all([getFood("first"), getFood("second"), getFood("third")]); 
promise.then(function(data) {
        let res = JSON.stringify(data);


});

context.res = {
     body:"This is text"
};
context.done();

它会在正文中返回字符串。

【问题讨论】:

    标签: javascript node.js json azure azure-function-app


    【解决方案1】:

    试试这个:

    module.exports = async function (context, req) {
       var data = await Promise.all([getFood("first"), getFood("second"),getFood("third")]); 
    
       return {
         body: JSON.stringify(data)
       };
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      相关资源
      最近更新 更多