Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解码php://input json_Php_Json_Input - Fatal编程技术网

解码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!英雄联盟