【问题标题】:Return both Variables in JSON返回 JSON 中的两个变量
【发布时间】:2022-01-04 07:05:01
【问题描述】:

如何将这两个变量都返回为 json,以便我可以从 Postman 读取它并在我的应用程序中使用?我有一些我想要得到的东西,比如获取一个 Base64string,然后调整它的大小并返回调整后的字符串

我的代码是这样的

app.post('/api/resizebase64', (req, res) =>{
    var base64str = req.body.base64tr;

    var frontendLogo = resizebase64(base64str, 112, 34);
    var emailLogo = resizebase64(base64str, 165, 50);

    if(error) throw error;
     //return the both variables as Json
});

我该怎么做? 请指出我正确的方向

【问题讨论】:

    标签: node.js rest resize


    【解决方案1】:

    app.post('/api/resizebase64', (req, res) => {
      var base64str = req.body.base64tr;
    
      var frontendLogo = resizebase64(base64str, 112, 34);
      var emailLogo = resizebase64(base64str, 165, 50);
    
      if (error) throw error;
      //return the both variables as Json
    
      res.json({
        frontendLogo,
        emailLogo
      })
    });

    【讨论】:

    • 谢谢,但它给出了一个错误,说文档文档没有定义
         在 module.exports
    • 如果您没有任何其他错误 res.json({ frontendLogo, emailLogo }) 应该可以解决您的问题。
    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 2014-11-19
    • 1970-01-01
    • 2015-06-04
    • 2014-12-22
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    相关资源
    最近更新 更多