每个SOAP请求StdClass

时间:2013-04-08 09:12:21

标签: php soap

我正在通过肥皂请求结果工作,但我坚持这个,因为它返回了超过1个结果。

请求基本上返回一个车库列表,其中包含我的邮政编码半径20英里。

任何人都可以帮助我吗?

这是我回来的结果:

stdClass Object
(
[SupplierDirectorySearchResult] => stdClass Object
    (
        [Status] => stdClass Object
            (
                [Code] => 0
                [Desc] => 
            )

        [SupplierCount] => 5
        [PageInfo] => stdClass Object
            (
                [PageNo] => 1
                [RowsPerPage] => 5
                [MaxPages] => 1
                [MaxRows] => 0
                [TotalRows] => 5
            )

        [Supplier] => Array
            (
                [0] => stdClass Object
                    (
                        [SiteRef] => AAAAA
                        [AccountRef] => 
                        [Name] => AAAAA AAAAA
                        [Address] => AAAAA AAAAA AAAAA
                                    AAAAA AAAAA
                                    AAAAA AAAAA AAAAA
                                    AAAAA
                                    AAAAA
                                    AAAAA
                                    AAAAA AAAAA
                        [Postcode] => AAAAA AAAAA
                        [Telephone] => AAAAA
                        [Fax] => AAAAA
                        [Email] => 
                        [InclusiveServices] => 
                        [ApprovedServices] => stdClass Object
                            (
                                [ServiceRepair] => Y
                                [MOT] => Y
                                [Tyres] => Y
                                [CollectionDelivery] => Y
                                [CourtesyCar] => Y
                                [WhileUWait] => 
                                [Callout24Hour] => Y
                                [BreakdownCover] => Y
                                [CollectionDeliveryNotes] => 
                                [CourtesyCarNotes] => 
                                [Inspections] => Y
                            )

                        [NextAvailableDate] => 2013-04-15T00:00:00
                        [AutomaticAcceptDate] => 2013-04-15T10:02:25.9664528+01:00
                        [NextAvailableDateStd] => 2013-04-15T00:00:00
                        [NextAvailableDateCandD] => 2013-04-15T00:00:00
                        [NextAvailableDateCCar] => 2013-04-15T00:00:00
                        [DistanceFromPostcode] => 3
                        [GridN] => 43327
                        [GridE] => 37842
                        [OpeningTime] => Array
                            (
                                [0] => stdClass Object
                                    (
                                        [Day] => 1
                                        [TimeFrom] => 10:00
                                        [TimeTo] => 16:00
                                    )

                                [1] => stdClass Object
                                    (
                                        [Day] => 2
                                        [TimeFrom] => 08:00
                                        [TimeTo] => 18:00
                                    )

                                [2] => stdClass Object
                                    (
                                        [Day] => 3
                                        [TimeFrom] => 08:00
                                        [TimeTo] => 18:00
                                    )

                                [3] => stdClass Object
                                    (
                                        [Day] => 4
                                        [TimeFrom] => 08:00
                                        [TimeTo] => 18:00
                                    )

                                [4] => stdClass Object
                                    (
                                        [Day] => 5
                                        [TimeFrom] => 08:00
                                        [TimeTo] => 18:00
                                    )

                                [5] => stdClass Object
                                    (
                                        [Day] => 6
                                        [TimeFrom] => 08:00
                                        [TimeTo] => 18:00
                                    )

                                [6] => stdClass Object
                                    (
                                        [Day] => 7
                                        [TimeFrom] => 10:00
                                        [TimeTo] => 16:00
                                    )

                            )

                        [FranchiseHeld] => stdClass Object
                            (
                                [Name] => Non-Franchised
                                [LabourRate] => 0
                                [PartsDiscount] => 0
                                [Preference] => P
                            )

                        [CSIPercentageRating] => 0
                        [Longitude] => -AAAAA9
                        [Latitude] => AAAAA
                        [StreetName] => AAAAA AAAAA
                        [LocalityName] => AAAAA
                        [TownName] => AAAAA
                        [CountyName] => AAAAA
                        [edeWebLinkURL] => 
                        [edeStrapLine] => 
                        [DropOffNotes] => 
                    )

                    )

            )

        [ClassVersion] => 1.0
    )

这是我用来尝试访问每个SiteRef的脚本:

foreach ($res->SupplierDirectorySearchResult->Supplier[0]->SiteRef as $SiteRef) {
  echo $SiteRef;
}

但这是我收到的错误消息:

无法将类stdClass的对象转换为

中的字符串

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

通过尝试遍历Supplier[0]->SiteRef,您实际上是在尝试对字符串进行foreach。您需要循环Supplier并在每次迭代时访问SiteRef,因为Supplier是可以循环的数组:

foreach ($res->SupplierDirectorySearchResult->Supplier as $supplier) {
  echo $supplier->SiteRef;
}