解码php://input json
我从解码php://input json,php,json,input,Php,Json,Input,我从文件获取内容('php://input): 如何引用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":1
文件获取内容('php://input)
:
如何引用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
$json='[{“电子邮件”:text@examlple.com“,“事件”:“已处理”,“sg_事件_id”:“JJTr9qA”,“sg_消息_id”:“AjvX5L7IQeGOfxmJV OCnw”,“smtp id”:“时间戳”:16813363}];
$obj=json_decode($json);
echo$obj[0]->电子邮件//输出text@examlple.com
您有一个数组,因此需要获取第一个元素:
$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
$json='[{“电子邮件”:text@examlple.com“,“事件”:“已处理”,“sg_事件_id”:“JJTr9qA”,“sg_消息_id”:“AjvX5L7IQeGOfxmJV OCnw”,“smtp id”:“时间戳”:16813363}];
$obj=json_decode($json);
echo$obj[0]->电子邮件//输出text@examlple.com
给你一个完整的答案:
<?php
$str = '[{"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($str);
echo $obj[0]->email;
给你一个完整的答案:
<?php
$str = '[{"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($str);
echo $obj[0]->email;
因为您的答案与之前发布的答案相同。删除你的答案是一种礼节(虽然我没有投你反对票),因为你的答案和之前发布的答案一样。删除你的答案是一种礼节(虽然我没有投你反对票)。如果你只想得到一个值,那就用一行代码:echo-json\u-decode(file\u-get\u-contents('php://input“))[0]->电子邮件代码>Wee!lol.One-line版本如果您只想得到一个值:echo json\u decode(file\u get\u contents('php://input“))[0]->电子邮件代码>Wee!英雄联盟