Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Parsing JSON Objects and Array
    primarykey
    data
    text
    <p>In the following code:</p> <pre><code>$.getJSON('&lt;?php echo $this-&gt;Html-&gt;url(array('controller'=&gt;'accounts', 'action'=&gt;'get_customers_order_mcs')); ?&gt;/'+customer_order_id, function(data){ var json_mc = data.MasterCarton.mc; alert(json_mc); $.each(json_mc,function(){ console.log(this); }); }); </code></pre> <p>The data sent as response is as follows-</p> <pre><code>{ "MasterCarton":{ "id":"40", "mc":"[ "1":{\"mc_number\":\"Warehouse1\\\/2013-2014\\\/CO\\\/ABC Corp\\\/239\\\/101-Red-1\",\"config\":{\"S2\":10,\"S1\":10},\"delivered\":0}, "2":{\"mc_number\":\"Warehouse1\\\/2013-2014\\\/CO\\\/ABC Corp\\\/239\\\/101-Red-2\",\"config\":{\"S2\":10,\"S1\":10},\"delivered\":0}, "3":{\"mc_number\":\"Warehouse1\\\/2013-2014\\\/CO\\\/ABC Corp\\\/239\\\/104-Black-3\",\"config\":{\"S1\":7,\"S2\":7,\"S5\":6},\"delivered\":0}, "4":{\"mc_number\":\"Warehouse1\\\/2013-2014\\\/CO\\\/ABC Corp\\\/239\\\/104-Black-4\",\"config\":{\"S1\":7,\"S2\":7,\"S5\":6},\"delivered\":0}, "5":{\"mc_number\":\"Warehouse1\\\/2013-2014\\\/CO\\\/ABC Corp\\\/239\\\/104-Black-5\",\"config\":{\"S1\":6,\"S2\":6,\"S5\":7},\"delivered\":0} ]", "delivery_note_id":"0", "customer_order_id":"314" } } </code></pre> <p>The json array inside of mc is as shown below-</p> <pre><code>[ "1":{ "mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-1", "config":{ "S2":10, "S1":10 }, "delivered":0 }, "2":{ "mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-2", "config":{ "S2":10, "S1":10 }, "delivered":0 }, "3":{ "mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/104-Black-5", "config":{ "S1":6, "S2":6, "S5":7 }, "delivered":0 } ] </code></pre> <p>I am trying to parse each object in it using jquery, and each object is as follows- </p> <pre><code> { "mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-1", "config":{ "S2":10, "S1":10 }, "delivered":0 } </code></pre> <p>To get the above object I using the following jquery code-</p> <pre><code>$.each(json_mc,function(){ // What should the code be so as to get each individual objects. }); </code></pre> <p>That is each and every time of .each should get me-</p> <pre><code> { "mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-1", "config":{ "S2":10, "S1":10 }, "delivered":0 } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload