【发布时间】:2020-07-04 15:50:49
【问题描述】:
您好,我正在尝试分解 JSON 数据
** {
"message": "gradeExam.php",
"id": "171",
"student_id": "dfd",
"questions": [{
"question_id": "0",
"student_input": "def doubly_"
},
{
"question_id": "1",
"student_input": "asd"
}
]
}**
使用 PHP
$json = file_get_contents('php://input');
$_POST = json_decode($json, true);
$input = $_POST["questions"];
foreach($input as $questions)
{
$quest_id[] = $questions["question_id"];
$student_input[] = $questions["student_input"];
}
echo $quest_id;
echo $student_input;
但不断收到...的响应。 ArrayArrayArray[]
我正在尝试循环并获取question_id:0,student_input:def double_,question_id:1,student_input:asd的数据。
我做错了什么?
【问题讨论】:
-
不能回显数组,使用
var_dump($quest_id, $student_input); -
array(2) { [0]=> string(1) "0" [1]=> string(1) "1" } array(2) { [0]=> string( 11) "def doubly_" [1]=> string(3) "asd" } ---这是我得到的回报
-
这不是你想要的吗?第一个是问题 ID 数组,第二个是输入数组。