我已经搜索过,但找不到答案。我的 PHP 脚本正在通过 http 帖子接收一些 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”。