我尋覓左右,但無法找到一個answer.My PHP腳本是通過接收HTTP POST一些JSON,看起來像這樣:PHP計數JSON陣列
{
"task": [
{
"task_id": "3",
"task_due": "Oct 26 11:25",
"task_completed": "FALSE",
"task_desc": "fff",
"task_time": "20131026_112531",
"task_name": "fff"
},
{
"task_id": "2",
"task_due": "Oct 26 11:25",
"task_completed": "FALSE",
"task_desc": "rff",
"task_time": "20131026_112522",
"task_name": "xff"
},
{
"task_id": "1",
"task_due": "Oct 26 11:25",
"task_completed": "FALSE",
"task_desc": "fggg",
"task_time": "20131026_112516",
"task_name": "ff"
}
]}
正如你所看到的,有3個項目,但是當我把它變成一個PHP數組對象和計數的項目,我返回1,當它應該是3,這是我的PHP代碼:
$json_tasks = $_POST["json_array"];
$task_array = json_decode($json_tasks,true);
echo count($task_array);
而且echo count
打印出「1」而不是「 3' 。
對不起我的錯,多了一個問題的探析即使世界上只有1個任務,而不是3,它說有6個任務 – AndroidDev
您錯誤地解釋數據結構。你嘗試過關於'var_export'的提示嗎? – Oswald