PHP访问JSON中的属性 [英] php accessing attributes in json

查看:354
本文介绍了PHP访问JSON中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在$response = $result->response;中存储了以下已解码的json:

I have the following already decoded json stored in $response = $result->response;:

 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,名称等):

I can already access the main attributes (EmailAddress, Name, etc) with:

$email = $response->{'EmailAddress'};
print $email;

但是我需要访问CustomFields对象中的"Value"部分.我不知道如何深入研究.我正尝试在PHP中执行此操作.

But I need to access the "Value" portion in the CustomFields object. I don't know how to dig that deep. I'm attempting to do this in PHP..

有什么建议吗?

推荐答案

它包含在数组CustomFields的第一个元素([0])中,因此之后可以使用对象运算符(->)访问它数组索引.

It is contained in the first element ([0]) of array CustomFields, so you can access it with an object operator (->) after the array index.

print $response->CustomFields[0]->Value;

这篇关于PHP访问JSON中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆