【问题标题】:Converting POST data from json-text to PHP objects?将 POST 数据从 json-text 转换为 PHP 对象?
【发布时间】:2017-10-29 17:06:39
【问题描述】:

我正在尝试设置自动电子邮件处理。我正在使用外部服务 https://www.email2json.net 将电子邮件转换为 JSON/文本格式,该格式在我网站的 webhook URL 上调用。

如何获取原始帖子数据并将其转换为 PHP 中的对象? 因此将电子邮件 jebrish 转换为有意义的东西?

谢谢。

【问题讨论】:

  • 我认为你需要 json_decode ?
  • idownvotedbecau.se/noattempt。最起码是发布你通过钩子获得的jebrish,以及你编写的尝试解析它的php代码。

标签: php json email post smtp


【解决方案1】:

你得到一个通过 POST 发送的 JSON 对象,所以你应该首先检索输入对象:

$input = file_get_contents("php://input");

然后您可以通过使用json_decode 原生函数将其转换为关联数组来轻松处理此 JSON 对象:

$decoded_input = json_decode($input, true);

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 2017-10-16
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多