简体   繁体   English

express.js响应值被破坏

[英]express.js response value as destruct

I think this is kind of destructuring problems.. 我认为这是一种破坏性的问题。

My node.js server have to return 我的node.js服务器必须返回

{
    "result" : true,
    "values" : [{
            "request_id": <string>,
            "product_name": <string>,
            "ratio": <float>,
            "buyers": [


        },
        ...
    ]
}

but it returns 但它返回

{"result":true,
"values":{"values":[{"results":[{"rank":1,"buyer_id":"Z0195841"},{"rank":2,"buyer_id":"Z0186008"},

I think this part is the problem. 我认为这是问题所在。

 res.json({ "result" : true,
            "values" : values});

so I edit like this, 所以我这样编辑

  res.json({ "result" : true,
               values});

it didn't works. 它没有用。 still return 仍然返回

{"result":true,
"values":{"values":[{

How can I solve this??? 我该如何解决??? please help. 请帮忙。

I think that you have a "value" inside other "value" key, try destructuring it, this way: 我认为您在其他“值”键中有一个“值”,请尝试通过以下方式对其进行分解:

const { value } = value;

res.json({ 
    "result" : true,
    values
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM