如何从以下HubSpot提供的供稿中获取电子邮件地址:
{
"contacts": [
{
"addedAt": 1390574181854,
"vid": 204727,
"canonical-vid": 204727,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2/",
"properties": {
"firstname": {
"value": "Bob"
},
"lastmodifieddate": {
"value": "1483461406481"
},
"company": {
"value": ""
},
"lastname": {
"value": "Record"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 204727,
"saved-at-timestamp": 1476768116149,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "LEAD_GUID",
"value": "f9d728f1-dff1-49b0-9caa-247dbdf5b8b7",
"timestamp": 1390574181878
},
{
"type": "EMAIL",
"value": "mgnew-email@hubspot.com",
"timestamp": 1476768116137
}
]
}
],
"merge-audits": [
]
},
{
"addedAt": 1392643921079,
"vid": 207303,
"canonical-vid": 207303,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P/",
"properties": {
"firstname": {
"value": "Ff_FirstName_0"
},
"lastmodifieddate": {
"value": "1479148429488"
},
"lastname": {
"value": "Ff_LastName_0"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 207303,
"saved-at-timestamp": 1392643921090,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "EMAIL",
"value": "email_0be34aebe5@abctest.com",
"timestamp": 1392643921079
},
{
"type": "LEAD_GUID",
"value": "058378c6-9513-43e1-a13a-43a98d47aa22",
"timestamp": 1392643921082
}
]
}
],
"merge-audits": [
]
}
],
"has-more": true,
"vid-offset": 207303
}
我能够使用下面的代码片段获取其他字段,例如名字和姓氏(我正在使用WordPress,因此使用以下代码复制确切的代码:wp_remote_get($ url,$ args))并在foreach内部具有以下代码:
foreach($y->contacts as $z) {
echo "First Name: " . $z->properties->firstname->value . '<br>';
echo "Last Name: " . $z->properties->lastname->value . '<br>';
}
答案 0 :(得分:1)
您好,您可以通过使用json_decode和true作为第二个参数来返回关联数组来做到这一点:
php:
<?php
$str = '{
"contacts": [
{
"addedAt": 1390574181854,
"vid": 204727,
"canonical-vid": 204727,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMusl38dq-ff-Lms9BvB5nWgFb7sFrDU98e-3CBdnB7G2qCt1pMEHC9zmqSfOkeq2on6Dz72P-iLoGjEXfLuWfvZRWBpkB-C9Enw6SZ-ZASg57snQun5f32ISDfLOiK7BYDL0l2/",
"properties": {
"firstname": {
"value": "Bob"
},
"lastmodifieddate": {
"value": "1483461406481"
},
"company": {
"value": ""
},
"lastname": {
"value": "Record"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 204727,
"saved-at-timestamp": 1476768116149,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "LEAD_GUID",
"value": "f9d728f1-dff1-49b0-9caa-247dbdf5b8b7",
"timestamp": 1390574181878
},
{
"type": "EMAIL",
"value": "mgnew-email@hubspot.com",
"timestamp": 1476768116137
}
]
}
],
"merge-audits": [
]
},
{
"addedAt": 1392643921079,
"vid": 207303,
"canonical-vid": 207303,
"merged-vids": [
],
"portal-id": 62515,
"is-contact": true,
"profile-token": "AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P",
"profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mPMwvuZG_QTNH28c_MbhSyNRuuTNw9I7zJAaMFjOqL9HKlH9uBteqHAiTRUWVAPTThuU-Fmy7IemUNUvdtYpLrsll6nw47qnu7ACiSHFR6qZP1tDVZFpxueESKiKUIIvRjGzt8P/",
"properties": {
"firstname": {
"value": "Ff_FirstName_0"
},
"lastmodifieddate": {
"value": "1479148429488"
},
"lastname": {
"value": "Ff_LastName_0"
}
},
"form-submissions": [
],
"identity-profiles": [
{
"vid": 207303,
"saved-at-timestamp": 1392643921090,
"deleted-changed-timestamp": 0,
"identities": [
{
"type": "EMAIL",
"value": "email_0be34aebe5@abctest.com",
"timestamp": 1392643921079
},
{
"type": "LEAD_GUID",
"value": "058378c6-9513-43e1-a13a-43a98d47aa22",
"timestamp": 1392643921082
}
]
}
],
"merge-audits": [
]
}
],
"has-more": true,
"vid-offset": 207303
}';
$arr_json = json_decode($str,true);
foreach($arr_json["contacts"] as $key=>$value){
foreach($value["identity-profiles"] as $key2 => $item){
foreach($item["identities"] as $key3 => $sub){
if($sub["type"] == "EMAIL"){
echo "\n";
echo $sub["value"];
}
}
}
//echo $value["value"];
};
?>
您可以在http://sandbox.onlinephpfunctions.com/
处尝试代码希望有帮助
答案 1 :(得分:1)
谢谢大家,我终于设法找到答案,这是我的粗略尝试(它基于WordPress的descriptionTextBox
):
deletes the file