0
我完全不熟悉XML。解析XML響應
,我使用下面的代碼:
$feed = file_get_contents($url);
$items = simplexml_load_string($feed);
print_r($items);
我有也嘗試使用simplexml_load_file()
,它顯示相同的錯誤。
我完全不熟悉XML。解析XML響應
,我使用下面的代碼:
$feed = file_get_contents($url);
$items = simplexml_load_string($feed);
print_r($items);
我有也嘗試使用simplexml_load_file()
,它顯示相同的錯誤。
file_get_contents
上的URL返回的是json類型的內容,這就是爲什麼simple_xml_load_file
無法解析它。使用這個
$feed = file_get_contents("https://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55504&minorRev=99&apiKey=cbrzfta369qwyrm9t5b8y8kf&locale=en_US¤cyCode=USD&xml=%3CHotelListRequest%3E%3Ccity%3ESeattle%3C%2Fcity%3E%3CstateProvinceCode%3EWA%3C%2FstateProvinceCode%3E%3CcountryCode%3EUS%3C%2FcountryCode%3E%3CarrivalDate%3E%3C%2FarrivalDate%3E%3CdepartureDate%3E9%2F1%2F2014%3C%2FdepartureDate%3E%3CRoomGroup%3E%3CRoom%3E%3CnumberOfAdults%3E2%3C%2FnumberOfAdults%3E%3C%2FRoom%3E%3C%2FRoomGroup%3E%3CnumberOfResults%3E25%3C%2FnumberOfResults%3E%3C%2FHotelListRequest%3E");
//echo $feed;
$json = json_decode($feed);
print_r($json);
當前在瀏覽器中查看它的xml,但在腳本中響應一個json。
$url = 'https://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55504&minorRev=99&apiKey=cbrzfta369qwyrm9t5b8y8kf&locale=en_US¤cyCode=USD&xml=%3CHotelListRequest%3E%3Ccity%3ESeattle%3C%2Fcity%3E%3CstateProvinceCode%3EWA%3C%2FstateProvinceCode%3E%3CcountryCode%3EUS%3C%2FcountryCode%3E%3CarrivalDate%3E%3C%2FarrivalDate%3E%3CdepartureDate%3E9%2F1%2F2014%3C%2FdepartureDate%3E%3CRoomGroup%3E%3CRoom%3E%3CnumberOfAdults%3E2%3C%2FnumberOfAdults%3E%3C%2FRoom%3E%3C%2FRoomGroup%3E%3CnumberOfResults%3E25%3C%2FnumberOfResults%3E%3C%2FHotelListRequest%3E';
$contents = file_get_contents($url);
$data = json_decode($contents, true);
// becomes an array
非常感謝..它的工作 – sss999 2014-08-30 08:41:47
關於如何打印結果的任何想法,我的願望,而不是一切,作爲結果得到打印爲對象的數組。我希望它只打印酒店的名字,而不是其他的東西 – sss999 2014-08-30 08:51:45
$ json = json_decode($ feed,true); $ arr = $ json ['HotelListResponse'] ['HotelList'] ['HotelSummary']; ($ arr as $ key => $ value) { print_r($ value [「name」]。「」); } – Sahil 2014-08-30 10:06:07