2013-03-05 65 views
-1

我不知道爲什麼,可能我只是爲了愚蠢,但我一直試圖從Expedia API請求中提取超過2小時的內容現在。今天我可能在這個網站上工作很久,所以我沒有看到一個簡單的錯誤,但無論如何我找不到它。 API Request「HotelList」對我造成了這個問題,從返回的XML輸出中獲取HotelDetails和提取數據工作得很好,並且第一次嘗試。Expedia API請求返回XML結果,但無法從中提取數據

請求/結果我得到了我的要求是這樣的:

$result = $search->getHotels($dataArray); 

-------------------------------------------- 

RESULT (print_r) LOOKS LIKE THIS 

    Array 
(
    [current_search] => Array 
     (
      [check_in] => 05/08/2013 
      [check_out] => 05/13/2013 
     ) 

    [title] => 
    [hotels] => SimpleXMLElement Object 
     (
      [customerSessionId] => XXXXXXXXXXXXX 
      [numberOfRoomsRequested] => 1 
      [moreResultsAvailable] => true 
      [cacheKey] => XXXXXXXXXXXXXXXXX 
      [cacheLocation] => XXXXXXXXXXXXXX 
      [cachedSupplierResponse] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [matchedLocale] => true 
          [matchedCurrency] => true 
          [tpidUsed] => 5102 
          [otherOverheadTime] => 5 
          [candidatePreptime] => 62 
          [supplierResponseTime] => 1950 
          [supplierResponseNum] => 5 
          [supplierRequestNum] => 513 
          [cachedTime] => 0 
          [supplierCacheTolerance] => NOT_SUPPORTED 
         ) 

       ) 

      [HotelList] => SimpleXMLElement Object 
       (
        [@attributes] => Array 
         (
          [activePropertyCount] => 562 
          [size] => 5 
         ) 

        [HotelSummary] => Array 
         (
          [0] => SimpleXMLElement Object 
           (
            [@attributes] => Array 
             (
              [ubsScore] => 2147483647 
              [order] => 0 
             ) 

            [hotelId] => 126913 
            [name] => The New Yorker Hotel 
            [address1] => 481 Eighth Ave. 
            [city] => New York 
            [stateProvinceCode] => NY 

我一直非常想一切辦法去這家酒店的名字,但我甚至不能提取CHECK_IN返回結果或類似的東西。我只是想嘗試像這樣的東西:

echo $result->hotels->HotelList->HotelSummary[0]->name; 
echo $result->HotelList->HotelSummary[0]->name; 
echo $result->$HotelSummary[0]->name; or 
echo $result->current_search->check_in; 

並可能像20其他組合,但根本沒有輸出。

我真的很希望有人能幫助我。

問候 托馬斯

+1

你能提供一個原始xml的樣本嗎?它的自身不是print_r格式將很高興看到你的完整的simplexml請求代碼。它可能是簡單/明顯的,但我今天有一個懶惰的大腦一天,所以想要真正運行它自己和測試 – Dave 2013-03-05 10:37:27

+0

得到它與使者,但非常感謝你的努力:) – wordsongoku 2013-03-05 10:49:24

+0

http://php.net /數組 - 可能重複的:[能夠看到print_r()的輸出中的變量,但不知道如何在代碼中訪問它](http://stackoverflow.com/questions/6322084/able-to-see- a-variable-in-print-rs-output-but-not-sure-how-to-access-it-in-c) – hakre 2013-03-05 10:50:11

回答

2

它看起來像:$result['hotels']->HotelList->HotelSummary[0]->name; 但OBV。未經測試。

+0

非常感謝你使者我只是沒有看到,但它現在就像一個魅力! :),當然,感謝戴夫的努力。 – wordsongoku 2013-03-05 10:47:26