使用 Node.js 通过 json 中的变量插入值
Inserting a value via a variable in json using Node.js
我必须使用 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"
}]
};
您可以使用变量作为您想要的任何值。
var thePrice = "25.00";
...
"amount": {
"currency": "USD",
"total": thePrice
},
我必须使用 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"
}]
};
您可以使用变量作为您想要的任何值。
var thePrice = "25.00";
...
"amount": {
"currency": "USD",
"total": thePrice
},