0
可以說我有一個JSON數組一樣如何在php中解碼json數組?
{
[
{"id" : 1, "src" : src1, "name" : name1},
{"id" : 2, "src" : src2, "name" : name2},
{"id" : 3, "src" : src3, "name" : name3},
{"id" : 4, "src" : src4, "name" : name4}
]
}
我應該怎麼解碼在PHP這個JSON陣列?
$project_info_json = $_POST['project_info_json'];
if (get_magic_quotes_gpc()) {
$project_info_json = stripslashes($_POST['project_info_json']);
}else {
$project_info_json = $_POST['project_info_json'];
}
$project_info_array = json_decode($project_info_json, true);
我已經嘗試json_decode方法,但它似乎像$ project_info_array有0個元素計數。有誰能告訴我我做錯了什麼?
這不是有效的JSON或有效的對象文本。我認爲你已經混淆了你的方括號和大括號 – Phil
仍然無效。丟失外部''}' – Phil
@Lee您是否創建了此json輸入...如果是這樣,請首先使用http://jsonlint.com/驗證它,並找出錯誤。然後使用json_decode()函數。 Php會爲你做。 –