2013-04-08 65 views
0

我正在通過肥皂請求結果工作,但由於它返回的結果超過1,所以我卡在這一個上。對於每個SOAP請求StdClass

該請求基本上返回了我的郵編半徑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; 
} 

但這是我得到的錯誤消息:

對象的分類s stdClass無法轉換爲字符串

任何人都可以幫我解決這個問題嗎?

回答

0

通過嘗試遍歷Supplier[0]->SiteRef,你實際上試圖對一個字符串做一個foreach。您需要循環Supplier並訪問在每次迭代的SiteRef,因爲Supplier是可以循環數組:

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

完美的感謝MrCode! – 2013-04-08 09:51:22