javascript - formatting a json object -


im trying use json store values page , access these values/variables later in php file. thing i'm new json , javascript in general , im struggling hours find solution problem might stupidly simple guys have experience in this: have this:

var invoice_data = {  "client":[ {     "client-name" : "",     "client-address" : "",     "client-address-2" : "",     "client-city-state" : "",         "client-country" : "" } ],  "shoppingcart":[      {     "1" : {"item-name":"", "qty":"", "price":"", "discount":"", "subtotal":""}     } ],  }; 

so inheritance thing im not getting. i've created "client" object im creating "shoppingcart", thing when user orders more item there should created sub-object store it's details too.so im assuming like:

"shoppingcart":[       {        "1" : { "item-name":"", "price":"", "discount":"" }     "2" : { "item-name":"", "price":"", "discount":"" }     } ], 

so when console.log(invoice_data.shoppingcart); "shoppingcart" object, cant access invoice_data.shoppingcart.1 or invoice_data.shoppingcart.2, there way can access 1 or 2 sub-object access invoice_data.shoppingcart or invoice_data.client?

thank you.

edit: can access array, im not interested in option. ideally i'd access sub-object via it's name.

remove array syntax:

change this:

"client":[ {     "client-name" : "",     "client-address" : "",     "client-address-2" : "",     "client-city-state" : "",     "client-country" : "" } ] 

to this:

"client": {     "client-name" : "",     "client-address" : "",     "client-address-2" : "",     "client-city-state" : "",     "client-country" : "" } 

the same goes shopping cart.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -