我通过对 PHP 页面的 HTTP POST 回调接收到一些 JSON,并且在解析 JSON 时遇到问题。下面是发送的 JSON 数据的示例:
[
{
"type" : "message-received",
"time" : "2016-09-14T18:20:16Z",
"description" : "Incoming message received",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : ["+12345678902"],
"from" : "+12345678901",
"text" : "Hey, check this out!",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"media" : [
"https://messaging.bandwidth.com/api/v2/users/{accountId}/media/14762070468292kw2fuqty55yp2b2/0/bw.png"
],
"owner" : "+12345678902",
"direction" : "in",
"segmentCount" : 1
}
}
]
然后我按如下方式处理:
$eventJSON = file_get_contents('php://input');
$event= json_decode( $eventJSON );
$eventType = $event->type;
但到目前为止我的$eventType变量没有得到任何东西 - 我认为问题可能是 JSON 是一个数组,但我不确定如何处理这个?
白衣非少年
慕容708150
随时随地看视频慕课网APP