【发布时间】: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