使用php访问json post数据

使用php访问json post数据,php,json,post,sendgrid,Php,Json,Post,Sendgrid,我正在编写一个小型PHP应用程序,它将从Send Grids Webhook API获取post数据,但它看起来像是将json作为post数据发送。我不知道如何访问这些数据。我以前使用过post数据,但我使用$\u post访问它,我从未收到过json post数据 这是我的代码,告诉我我是否走对了方向 include 'send_grid_conn.php'; $dealer = (isset($_GET['dealer']) && !empty($_GET['dealer']

我正在编写一个小型PHP应用程序,它将从Send Grids Webhook API获取post数据,但它看起来像是将json作为post数据发送。我不知道如何访问这些数据。我以前使用过post数据,但我使用$\u post访问它,我从未收到过json post数据

这是我的代码,告诉我我是否走对了方向

include 'send_grid_conn.php';
$dealer = (isset($_GET['dealer']) && !empty($_GET['dealer']))?$_GET['dealer']:"N/A";
echo $dealer;

$postData = json_decode($HTTP_RAW_POST_DATA,true);

$email = (isset($postData['email']))?$postData['email']:"nothing";

    $stmt = $connection->prepare("INSERT INTO `send_grid`(`email`, `dealer`) VALUES (?,?)");
    $stmt->execute(array($email, $dealer));
插入部分工作,但我无法访问POST数据

顺便说一句,我将清理代码。现在我只是在测试模式下尝试访问json数据。

$HTTP_RAW_POST_数据在PHP5.6中被弃用,在PHP7中被删除,您应该使用php://input 因为它不依赖于任何php.ini配置,而且,您是否尝试解码$\u POST?。在请求中,json只是一个字符串,因此您不应该有任何问题

与php://input:

美元邮政:

尝试使用var_dump$postData查看数组包含的内容。
json_decode(php://input, true);
json_decode($_POST, true);