次のコードでは:
$.getJSON('<?php echo $this->Html->url(array('controller'=>'accounts', 'action'=>'get_customers_order_mcs')); ?>/'+customer_order_id,
function(data){
var json_mc = data.MasterCarton.mc;
alert(json_mc);
$.each(json_mc,function(){
console.log(this);
});
});
応答として送信されるデータは次のとおりです。
{
"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"
}
}
mc 内の json 配列は次のとおりです。
[
"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
}
]
jqueryを使用して各オブジェクトを解析しようとしていますが、各オブジェクトは次のとおりです-
{
"mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-1",
"config":{
"S2":10,
"S1":10
},
"delivered":0
}
上記のオブジェクトを取得するには、次のjqueryコードを使用します-
$.each(json_mc,function(){
// What should the code be so as to get each individual objects.
});
それは毎回です.eachは私を得る必要があります-
{
"mc_number":"Warehouse1\/2013-2014\/CO\/ABC Corp\/239\/101-Red-1",
"config":{
"S2":10,
"S1":10
},
"delivered":0
}