SimpleXMLElement循环的对象响应

时间:2017-09-18 01:50:32

标签: php arrays for-loop simplexml

我试图从Xero API返回联系人列表但是当从那里获得响应时,我无法通过for循环运行数组。

当试图循环显示任何内容时,过去是否有人遇到此问题?

我试图循环将每个联系人放在一个表格内的一行中。

如果我跑

pr($contacts->Contacts[0]);

它会返回联系人列表,但它不会显示任何带有for循环

的内容

这是我的for循环

foreach($contacts->Contacts[0] as $item) {
echo $item['Id'];
echo $item['filepath'];
}   

这是返回的数组

SimpleXMLElement Object
(
[Id] => 0dcda838-d354-4674-b6eb-d788e166b8dd
[Status] => OK
[ProviderName] => TestIntergration
[DateTimeUTC] => 2017-09-18T01:42:30.7361585Z
[Contacts] => SimpleXMLElement Object
    (
        [Contact] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [ContactID] => 0ae2c0f4-cae9-4431-ab6b-52554f1c7c69
                        [ContactStatus] => ACTIVE
                        [Name] => Steve Buscemi
                        [Addresses] => SimpleXMLElement Object
                            (
                                [Address] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [AddressType] => STREET
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [AddressType] => POBOX
                                            )

                                    )

                            )

                        [Phones] => SimpleXMLElement Object
                            (
                                [Phone] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DDI
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DEFAULT
                                            )

                                        [2] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => FAX
                                            )

                                        [3] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => MOBILE
                                            )

                                    )

                            )

                        [UpdatedDateUTC] => 2017-08-30T08:14:03.88
                        [IsSupplier] => false
                        [IsCustomer] => true
                        [HasAttachments] => false
                    )

                [1] => SimpleXMLElement Object
                    (
                        [ContactID] => ab8a9286-740e-4246-876c-9fcac558d600
                        [ContactStatus] => ACTIVE
                        [Name] => Martin Hudson
                        [Addresses] => SimpleXMLElement Object
                            (
                                [Address] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [AddressType] => STREET
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [AddressType] => POBOX
                                            )

                                    )

                            )

                        [Phones] => SimpleXMLElement Object
                            (
                                [Phone] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DDI
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DEFAULT
                                            )

                                        [2] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => FAX
                                            )

                                        [3] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => MOBILE
                                            )

                                    )

                            )

                        [UpdatedDateUTC] => 2017-08-30T08:20:03.263
                        [IsSupplier] => false
                        [IsCustomer] => true
                        [HasAttachments] => false
                    )

                [2] => SimpleXMLElement Object
                    (
                        [ContactID] => 463e9f23-d1a1-4d74-b19e-041142c8fd34
                        [ContactStatus] => ACTIVE
                        [Name] => Orlena Greenville
                        [Addresses] => SimpleXMLElement Object
                            (
                                [Address] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [AddressType] => STREET
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [AddressType] => POBOX
                                            )

                                    )

                            )

                        [Phones] => SimpleXMLElement Object
                            (
                                [Phone] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DDI
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DEFAULT
                                            )

                                        [2] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => FAX
                                            )

                                        [3] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => MOBILE
                                            )

                                    )

                            )

                        [UpdatedDateUTC] => 2017-09-01T07:56:32.667
                        [IsSupplier] => false
                        [IsCustomer] => false
                        [HasAttachments] => false
                    )

                [3] => SimpleXMLElement Object
                    (
                        [ContactID] => b75bfe5b-cc6e-45ee-b0a1-feafe866088d
                        [ContactStatus] => ACTIVE
                        [Name] => asdfasdfasdf454
                        [Addresses] => SimpleXMLElement Object
                            (
                                [Address] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [AddressType] => STREET
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [AddressType] => POBOX
                                            )

                                    )

                            )

                        [Phones] => SimpleXMLElement Object
                            (
                                [Phone] => Array
                                    (
                                        [0] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DDI
                                            )

                                        [1] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => DEFAULT
                                            )

                                        [2] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => FAX
                                            )

                                        [3] => SimpleXMLElement Object
                                            (
                                                [PhoneType] => MOBILE
                                            )

                                    )

                            )

                        [UpdatedDateUTC] => 2017-09-04T10:34:52.93
                        [IsSupplier] => false
                        [IsCustomer] => false
                        [HasAttachments] => false
                    )

            )

    )

)

用于获取传递数据的代码

$response = $XeroOAuth->request('GET', $XeroOAuth->url('Contacts', 'core'), array());
if ($XeroOAuth->response['code'] == 200) {
 $contacts = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);           
 pr($contacts);
}       

0 个答案:

没有答案