【发布时间】:2017-01-18 04:03:37
【问题描述】:
我有一个 json 字符串类型转换为 std 对象。由 AWS SNS 返回,一些被转换为数组,一些被转换为标准对象属性。我正在尝试从中解码属性“[bouncedRecipients]”,它有时是一个数组,有时它是一个 std 对象属性。
无法使用它,因为我尝试了以下代码,该代码仅在它是 JSON 对象属性但不能作为数组工作时才有效。
$mail=json_decode($data->bounce->bouncedRecipients);
这里是返回数据类型的示例。其他变体类型 [bouncedRecipients] 成为标准对象属性。
[2016-09-10 04:15:10] SNS 邮件
stdClass Object
(
[notificationType] => Bounce
[bounce] => stdClass Object
(
[bounceType] => Permanent
[bounceSubType] => Suppressed
[bouncedRecipients] => Array
(
[0] => stdClass Object
(
[emailAddress] => exmaple@gmail.com
[action] => failed
[status] => 5.1.1
[diagnosticCode] => Amazon SES has suppressed sending to this address because it has a recent history of bouncing as an invalid address. For more information about how to remove an address from the suppression list, see the Amazon SES Developer Guide: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/remove-from-suppressionlist.html
)
)
[timestamp] => 2016-09-09T22:45:24.978Z
[feedbackId] => 01000157112sasasec-76df-11e6-9e95-5db9bsasas-000000
[reportingMTA] => dns; amazonses.com
)
[mail] => stdClass Object
(
[timestamp] => 2016-09-09T22:45:05.000Z
[source] => info@example.com
[sourceArn] => arn:aws:ses:ssss.com
[sendingAccountId] => 973549asasas9
[messageId] => 0100015711207assaasa-4c54-afb2-34f9868a4e1c-000000
[destination] => Array
(
[0] => example@gmail.com
)
)
)
【问题讨论】:
标签: php json amazon-sns