【问题标题】:Inserting a value via a variable in json using Node.js使用 Node.js 通过 json 中的变量插入值
【发布时间】:2020-11-08 00:55:49
【问题描述】:

我必须使用 json 中的变量写入特定值。下面是代码。 我需要写一个包含价格的变量而不是价格,有人可以指导如何做到这一点。

app.post('/pay', (req, res) => {
  const create_payment_json = {
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://localhost:3000/success",
        "cancel_url": "http://localhost:3000/cancel"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                "name": "Red Sox Hat",
                "sku": "001",
                "price": "25.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "currency": "USD",
            "total": "25.00"
        },
        "description": "Hat for the best team ever"
    }]
};

【问题讨论】:

  • 价格:some_value, ...
  • 或者你可以使用 transactions[0].item_list.items[0].price = priceValue

标签: node.js json fs


【解决方案1】:

您可以将变量用于您想要的任何值。

var thePrice = "25.00";

...

"amount": {
            "currency": "USD",
            "total": thePrice
        },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2014-05-19
    • 2017-07-17
    相关资源
    最近更新 更多