【问题标题】:Parsing big json data with php [closed]用php解析大json数据[关闭]
【发布时间】:2015-08-19 05:13:00
【问题描述】:

我有一个这样的 json:

[
    {
        "event": "hard_bounce",
        "_id": "323418ee24f744859ce7b7e01f28e0d1",
        "msg": {
            "ts": 1433426374,
            "_id": "323418ee24f744859ce7b7e01f28e0d1",
            "state": "bounced",
            "subject": "Subject",
            "email": "testMail@hotmail.com",
            "tags": [],
            "smtp_events": [],
            "resends": [],
            "_version": "HM-1sBYhpAPYoUvSCE2-Zw",
            "diag": "smtp;550 Requested action not taken: mailbox unavailable",
            "bgtools_code": 10,
            "sender": "noreply@domain.net",
            "template": null,
            "bounce_description": "bad_mailbox"
        },
        "ts": 1433427203
    }
]

我必须得到email 的值。我怎么才能得到它?我的意思是我必须得到testMail@hotmail.com

我如何用 php 做到这一点?

【问题讨论】:

  • 到目前为止你尝试过什么?你甚至用谷歌搜索过这个,因为它很简单。你使用json_decode
  • PHP 为这些事情提供了许多方便的函数。你应该搜索这样的东西。例如 json 提供了反序列化 json 编码数据的功能。
  • 顺便说一句,您似乎在请求 mandrill 或 mailchimp api。他们有图书馆。

标签: php


【解决方案1】:

你可以这样做:

$decoded = json_decode($myJson);
echo $decoded[0]->msg->email;

【讨论】:

  • 返回 null。
  • 不,我没有用你的 JSON 测试过。你做错了什么。
  • 好吧,那是我的错。非常感谢。
【解决方案2】:

您可以使用json_decode() 以这种方式获取变量。

来自手册:

<?php

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    相关资源
    最近更新 更多