0

これはおそらく単純ですが、私は頭がおかしいです。

私はAPIを使用しています。$checkLead を宣言し、下に表示される stdClassObject を取得します。配列の値を取得しようとしています。この例では 1 つのレコードがありますが、将来はさらに多くのレコードが含まれる可能性があります。

これは、print_r を実行したときに出力されるものです。

stdClass Object ( 
    [result] => stdClass Object ( 
        [count] => 1 
        [leadRecordList] => stdClass Object ( 
            [leadRecord] => stdClass Object ( 
                [Id] => 26 
                [Email] => test3@test.com 
                [ForeignSysPersonId] => 
                [ForeignSysType] => 
                [leadAttributeList] => stdClass Object ( 
                    [attribute] => Array ( 
                        [0] => stdClass Object ( 
                            [attrName] => FirstName 
                            [attrType] => string 
                            [attrValue] => JJ 
                        )
                        [1] => stdClass Object ( 
                            [attrName] => LastName 
                            [attrType] => string 
                            [attrValue] => JJ 
                        ) 
                        [2] => stdClass Object ( 
                            [attrName] => Website 
                            [attrType] => url 
                            [attrValue] => test.com 
                        )
                    )
                )
            )
        )
    )
)

複数の結果が返される例を次に示します。

stdClass Object (
[result] => stdClass Object (
    [count] => 2
    [leadRecordList] => stdClass Object (
        [leadRecord] => Array (
            [0] => stdClass Object (
                [Id] => 33
                [Email] => test3@test.com
                [ForeignSysPersonId] =>
                [ForeignSysType] =>
                [leadAttributeList] => stdClass Object (
                    [attribute] => Array (
                        [0] => stdClass Object (
                            [attrName] => FirstName
                            [attrType] => string
                            [attrValue] => jj )
                        [1] => stdClass Object (
                            [attrName] => LastName
                            [attrType] => string
                            [attrValue] => amonit )
                        [2] => stdClass Object (
                            [attrName] => Website
                            [attrType] => url
                            [attrValue] => test.com )
                        )
                    )
                )
            [1] => stdClass Object (
                [Id] => 26
                [Email] => test3@test.com
                [ForeignSysPersonId] =>
                [ForeignSysType] =>
                [leadAttributeList] => stdClass Object (
                    [attribute] => Array (
                        [0] => stdClass Object (
                            [attrName] => FirstName
                            [attrType] => string
                            [attrValue] => bob )
                        [1] => stdClass Object (
                            [attrName] => LastName
                            [attrType] => string
                            [attrValue] => smith )
                        [2] => stdClass Object (
                            [attrName] => Phone
                            [attrType] => phone
                            [attrValue] => 123-123-1234 )
                        [3] => stdClass Object (
                            [attrName] => Website
                            [attrType] => url
                            [attrValue] => test.com )
                        )
                    )
                )
            )
        )
    )
)

それで、誰かが の値を取得するのを手伝ってくれるかどうか疑問に思っていましたFirstNameLastNameまた、「が にFirstName等しいの値は何ですか"JJ"

4

4 に答える 4

0

ファースト ネームを取得するには、Marketo から複数のリードが返されるか、最良の場合は 1 つのリードが返される可能性があります。その情報を取得するためのコードを次に示します。お役に立てれば。

if (is_object($checkLead)) {
    $leadRecord = $checkLead->result->leadRecordList->leadRecord;
    if (is_array($leadRecord)) {
        //multiple leads returned
        //run another foreach within a forloop to get the same values
        for($x=0; $x<sizeof($leadRecord); $x++) {
            $LeadAttribute = $leadRecord[$x]->leadAttributeList->attribute;
            foreach($LeadAttribute as $attribute) {
                if($attribute->attrName == 'FirstName') {
                    echo "\nFirst Name: ".$attribute->attrValue;
                }
            }
        }
    } else {
        //single lead returned
        $LeadAttribute = $leadRecord->leadAttributeList->attribute;
        foreach($LeadAttribute as $attribute) {
            if($attribute->attrName == 'FirstName') {
                echo "\nFirst Name: ".$attribute->attrValue;
            }
        }
    }

}
于 2013-09-23T21:31:16.123 に答える
-1

Array への単純なキャストにより、stdClassObject にすぐにアクセスできるようになります。

$myArray = (array)$myUnusableObject;

echo 'What have we here? '.var_export($myArray, true);
于 2013-09-20T20:29:50.023 に答える