For example, now there is a json object called jsonObj, you need to add a new attribute newParam to this object, and assign the value new to newParam. The method is as follows:
var jsonObj={
'param1': 111,
'param2': 222
};
Add new attribute: newParam = 'new
jsonObj. newParam ='new';
After the new attribute is added, the json object becomes:
var jsonObj={
'param1': 111,
'param2': 222,
'newParam':'new'
};
Application in actual scenarios, for example, I need a jump with parameters:
// 立即购买
confirmBuy() {
this.show = false;
uni.navigateTo({
url: "/pages/settlecenter/settlecenter?goods=" +
JSON.stringify(this.optitem),
});
},
The json structure that needs to be passed is as follows: this.optitem
optitem: [{
StockNum: "497",
articleId: "9066",
goods_xl: "5",
hasRelated: "1",
images: [{
id: '001',
Path: ["https://xxx/images/myIcon/recommend1.png"],
},
{
id: '002',
Path: ["https://xxx/images/myIcon/recommend1.png"],
}
],
isInStock: "1",
isStock: "1",
markingPrice: "450.00",
name: "示例商品1",
original_price: "450.00",
price: "410.00",
price_mh: "",
unitPrice: "410.00",
},
Now you need to add a new attribute count to the above json object, written as [ this.optitem.count = e.value ]
// 购物车的数值发生改变
changeNumberBox(e) {
console.log("值发生改变 ", e.value);
// 添加新属性
this.optitem.count = e.value
// this.count = e.value
console.log("548",this.optitem);
}