我正在尝试以JSON格式提交表单输入。在将JSON数据解码为数组后,我无法访问该数组。
{
"info": {
"q_title": "hello",
"q_description": "ddd",
"q_visibility": "1",
"start_date": "Thu, 05 Oct 2017 06:11:00 GMT"
}
}
这是我的JSON数据。我的Laravel控制器如下:
public function store_quiz(Request $request)
{
$data = json_decode($request->getContent(), true);
$input = $arrayName = array(
'title' => $data["info"]["q_title"],
);
CreateQuiz::create($input);
$redirect = '/';
return $redirect;
}
很遗憾$data["info"]["q_title"]
返回NULL。如何访问我的JSON的“q_tittle”?
$request->getContent()
返回什么?它是 JSON 编码的字符串吗? 此外,您确定您尝试访问的 JSON 编码字符串始终具有上述属性吗? - Yaman Jain