HubSpot api json decode


HubSpot api json decode

我正在尝试从Hubspot API响应中解析一些数据。响应看起来像这样json_edecoded:

stdClass Object(
[addedAt] => 1411052909604
[vid] => 24
[canonical-vid] => 24
[merged-vids] => Array
    (
    )
[portal-id] => XXXXX
[is-contact] => 1
[profile-token] => AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[profile-url] => https://app.hubspot.com/contacts/XXXXX/lists/public/contact/_AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[properties] => stdClass Object
    (
        [lastname] => stdClass Object
            (
                [value] => testtt
            )
        [firstname] => stdClass Object
            (
                [value] => test
            )
        [lastmodifieddate] => stdClass Object
            (
                [value] => 1411052906670
            )
    )
[form-submissions] => Array
    (
        [0] => stdClass Object
            (
                [conversion-id] => 85d24dd2-9ee9-4d47-b8f3-3035acbd8f3b
                [timestamp] => 1411052834097
                [form-id] => fb16efd9-23cc-4511-889c-204fc8b41dba
                [portal-id] => 401824
                [page-url] => http://wbl-1.hs-sites.com/test
                [canonical-url] => http://wbl-1.hs-sites.com/test
                [content-type] => landing-page
                [page-title] => test
                [page-id] => 1570433242
                [title] => Default Form (Sample)
                [first-visit-url] => http://wbl-1.hs-sites.com/test
                [first-visit-timestamp] => 1411052722970
                [meta-data] => Array
                    (
                    )
            )
    )
[list-memberships] => Array
    (
    )
[identity-profiles] => Array
    (
        [0] => stdClass Object
            (
                [vid] => 24
                [identities] => Array
                    (
                        [0] => stdClass Object
                            (
                                [type] => EMAIL
                                [value] => test@user.com
                                [timestamp] => 1411052834097
                            )
                        [1] => stdClass Object
                            (
                                [type] => LEAD_GUID
                                [value] => 0b6acf21-6cee-4c7b-b664-e65c11ee2d8e
                                [timestamp] => 1411052834201
                            )
                    )
            )
    )
[merge-audits] => Array
    (
    )

)

我特别想在身份档案区找到一封电子邮件。

我试着做了以下事情:

echo $results->contacts[0]->identity-profiles;

但它只给了我0 的值

然后我尝试通过以下操作进一步深入阵列:

echo $results->contacts[0]->identity-profiles[0];

但在这一点上,我得到了一个解析错误:

分析错误:语法错误,意外的"["

我做错了什么?我怎么能一直挖到身份配置文件[0]->身份->[0]->值

其应等于:test@user.com

我错过了什么?

如注释中所述,我建议通过将true作为第二个参数传递给json_decode来将JSON解码为关联数组。示例:json_decode($data, true)您可以通过以下方式访问您的身份配置文件:

$results['contacts'][0]['identitiy-profiles']

如果您仍然想将结果作为对象获取,则必须以以下方式访问属性,因为它们包含-:

$results->contacts[0]->{'identity-profiles'}