这是我现有的json:
var _cartInfo;
var _cart = localStorage.getItem("w3lssbmincart");
_cart = decodeURIComponent(_cart);
_cart = JSON.parse(_cart);
_cart返回:
{
"value": {
"items": [{
"cmd": "_cart",
"add": "1",
"w3ls_item": "MIXZA TOHAOLL 128GB",
"amount": 52.53,
"quantity": 1,
"href": "localhost:27524/Home.aspx"
}, {
"cmd": "_cart",
"add": "1",
"w3ls_item": "Huawei 1",
"amount": 0.99,
"quantity": 2,
"href": "localhost:27524/Telemovel.aspx"
}, {
"cmd": "_cart",
"add": "1",
"w3ls_item": "Apple 1",
"amount": 1.09,
"quantity": 1,
"href": "localhost:27524/"
}],
"settings": {
"bn": "sbmincart_AddToCart_WPS_US"
}
},
"expires": "Thu, 27 Jul 2017 17:07:45 GMT"
}
如何使变量只包含这样的项目:
{
"items": [{
"cmd": "_cart",
"add": "1",
"w3ls_item": "MIXZA TOHAOLL 128GB",
"amount": 52.53,
"quantity": 1,
"href": "localhost:27524/Home.aspx"
}, {
"cmd": "_cart",
"add": "1",
"w3ls_item": "Huawei 1",
"amount": 0.99,
"quantity": 2,
"href": "localhost:27524/Telemovel.aspx"
}, {
"cmd": "_cart",
"add": "1",
"w3ls_item": "Apple 1",
"amount": 1.09,
"quantity": 1,
"href": "localhost:27524/"
}]
}
感谢您提前回复。
答案 0 :(得分:3)
var _newCart = {};
_newCart['items'] = _cart['value']['items'];