我有以下代碼:我應該使用JSON數組還是對象?
$.each(orderedqty, function(priority, quantity) {
// for each priority
if ($(".switch[data-priorityid=" + priority + "]").attr("data-state") == "on") {
// this priority is checked
orderedqtyArray[ priority ] = 15;
} else {
orderedqtyArray[ priority ] = 10;
}
});
console.info(orderedqtyArray);
console.info(JSON.stringify(orderedqtyArray));
問題是這樣的代碼返回:
[77:15,78:15]
[NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,15,15][78:15]
[null,null,null,null,null,null,null,null,null,null,null,null, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,15]
取而代之的是漂亮的JSON :(
所以你創建一個sparce陣列,當你將其轉換成JSON你......一個sparce陣列。有什麼問題? – Quentin 2014-10-08 09:46:16
'orderedqty'看起來像?你能分享它 – Navin 2014-10-08 09:46:16
這是一個美麗的JSON,一切都很正常:) – xShirase 2014-10-08 09:48:44