javascript - Can't log object details from parsed JSON? -




i have no problem logging following:

<h1>order list</h1>  <ul>      <%orders.foreach(function(order){%>         <li><%console.log(order.shippingaddress);%></li>     <%});%> </ul> 

but when attempt log this:

<h1>order list</h1>  <ul>      <%orders.foreach(function(order){%>         <li><%console.log(order.shippingaddress.name);%></li>     <%});%> </ul> 

i error:

cannot read property 'name' of undefined 

i must overlooking simple because "name" exists... not setting correctly. ideas?

here data looks each 'order':

{ amazonorderid: '99999',   purchasedate: 'date',   lastupdatedate: 'date',   orderstatus: 'shipped',   fulfillmentchannel: 'mfn',   saleschannel: 'amazon.com',   shipservicelevel: 'std d2d dom',   shippingaddress:      { name: 'name here',       addressline1: 'address here',       city: 'city',       stateorregion: 'state',       postalcode: '999999',       countrycode: 'us' } 

i can work using php following way:

<?php     $string = file_get_contents('./data/store.json');     $data = json_decode($string, true);       foreach($data[listordersresult][orders][order] $order) {         print_r("<li>".$order[shippingaddress][name]."</li>");     } ?> 

are sure first snippet contains shippingaddress data?

there might 1 specific order (or more) no shipping information? try dropping console.log(order.amazonorderid) before trying display name , you'll see order it's stopping on.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -