2017-06-28 12 views
-2

は、これは私が持っている現在のJSONです:トラブル編集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

'_cart = decodeURIComponent(_cart);'は何のために必要ではありませんか? – EvgenyKolyakov

+0

'_cart = _cart.value' – Weedoze

答えて

3
var _newCart = {}; 
_newCart['items'] = _cart['value']['items']; 
関連する問題