我在 $response = $result->response;
中存储了以下已经解码的 json:
object(stdClass)#6 (5) {
["EmailAddress"]=> string(18) "email@gmail.com"
["Name"]=> string(0) ""
["Date"]=> string(19) "2011-10-09 19:32:00"
["State"]=> string(6) "Active"
["CustomFields"]=> array(1) {
[0]=>object(stdClass)#7 (2) {
["Key"]=>string(2) "id"
["Value"]=>string(6) "Dl9lIz"
}
}
我已经可以访问主要属性(EmailAddress、Name 等):
$email = $response->{'EmailAddress'};
print $email;
但我需要访问 CustomFields 对象中的 "Value"
部分。我不知道如何挖掘那么深。我正在尝试用 PHP 执行此操作..
有什么建议吗?
最佳答案
它包含在数组 CustomFields
的第一个元素 ([0]
) 中,因此您可以使用对象运算符 (->> 访问它
) 在数组索引之后。
print $response->CustomFields[0]->Value;
关于php访问json中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8000412/