gpt4 book ai didi

PHP - 解析 JSON 有效负载问题

转载 作者:行者123 更新时间:2023-12-03 01:34:13 24 4
gpt4 key购买 nike

我通过对 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 是一个数组,但我不确定如何处理这个问题?

最佳答案

解析 json 尝试

$eventType = $event[0]->type;

引用:- How do I extract data from JSON with PHP?了解对象属性和数组元素之间的区别

关于PHP - 解析 JSON 有效负载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59779977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com