0

私は石鹸リクエストの結果を処理していますが、複数の結果を返すため、これに固執しています。

このリクエストは基本的に、私の郵便番号から半径 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 のオブジェクトを文字列に変換できませんでした

誰でもこれについて私を助けることができますか?

4

1 に答える 1

0

をループしようSupplier[0]->SiteRefとすることで、実際には文字列に対して foreach を実行しようとしています。はループできる配列であるため、各反復でループSupplierしてアクセスする必要があります。SiteRefSupplier

foreach ($res->SupplierDirectorySearchResult->Supplier as $supplier) {
  echo $supplier->SiteRef;
}
于 2013-04-08T09:30:48.193 に答える