+
81
-

php怎么接受post过来的json数据?

php

$_POST,可以接受网页的form post数据,那怎么接受json post数据呢?

网友回复

+
1
-
/** * 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json * @return array */ private function initPostData() { if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) { $content = file_get_contents('php://input'); $post = (array)json_decode($content, true); } else { $post = $_POST; } return $post; }
我知道答案,我要回答