1
我建立一個數組中的JS這樣:JSON對象到PHP關聯數組
var slots = {};
$(".taken").each(function(item) {
var key = $(this).attr("id");
slots[key] = "<?php echo $_SESSION['alias']; ?>";
});
var json = JSON.stringify(slots);
var date = "<?php echo $_GET['date']; ?>"
$.ajax({
type: "POST",
url: "controllers/dutyupdate2.php",
data:{ array : json, date: date },
success : function(response){
console.log (response)
}//end success
});//end ajax
在我的PHP腳本我張貼到,我需要對它進行解碼,以匹配以下格式:
array('D1P'=>"JohnC" , 'D6E' => "JohnC")
我得到:
Array(
[D2E] => JohnC
[D6E] => JohnC
[D3BU] => JohnC
)
不管我怎麼陣列解碼,我得到一個索引數組我作爲索引鍵。 我在JS代碼中錯誤地構建了數組還是錯誤地解碼?
在此先感謝
你如何解碼......你可以使用json_decode($ data,TRUE); – 2013-02-14 15:15:24
「我得到一個以索引爲索引的索引數組」 - 你究竟想要什麼*? – 2013-02-14 15:16:43
我不明白這兩個數組是如何不同的(你得到的那個,你想要的) – 2013-02-14 15:17:24