我有以下这段文字file_get_contents('php://input'):
[{"email":"text@examlple.com","event":"processed","sg_event_id":"JJTr9qA","sg_message_id":"AjvX5L7IQeGOfxmJV-OCnw","smtp-id":"<AfxmJV-OCnw@ismon1.sendgrid.net>","timestamp":16813363}]
Run Code Online (Sandbox Code Playgroud)
我需要获取电子邮件或事件之类的单个元素,但无法获取json_decode,其他人也无法使用。
$obj = json_decode(file_get_contents('php://input'));
Run Code Online (Sandbox Code Playgroud)
如何引用json数据中的单个元素?
您有一个数组,因此,需要获取第一个元素:
$json = '[{"email":"text@examlple.com","event":"processed","sg_event_id":"JJTr9qA","sg_message_id":"AjvX5L7IQeGOfxmJV-OCnw","smtp-id":"<AfxmJV-OCnw@ismon1.sendgrid.net>","timestamp":16813363}]';
$obj = json_decode($json);
echo $obj[0]->email; //output text@examlple.com
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |