gpt4 book ai didi

javascript - 尝试使用 simplexml 访问 ean 酒店列表中的名称

转载 作者:行者123 更新时间:2023-12-02 17:04:56 26 4
gpt4 key购买 nike

我正在尝试使用 simplexml 从 api 访问酒店名称,显示酒店列表。

到目前为止我已经使用过这段代码。这对我来说似乎是正确的,但我仍然无法让它工作。

<?php

$xml_file = 'http://dev.api.ean.com/ean-services/rs/hotel/v3/list?minorRev=99&apiKey=ycdydfqdz4w5huxv4psfxs8h&cid=55505&locale=en_US&currencyCode=USD&supplierCacheTolerance=MED_ENHANCED&countryCode=US&city=Dallas&stateProvinceCode=TX&searchRadius=50&numberOfResults=20&arrivalDate=08/31/2014&departureDate=09/15/2014&minRate=100&maxRate=1000&room1=1&numberOfAdults=2';
$xml = simplexml_load_file($xml_file);

$response = $xml->HotelListResponse->HotelList->HotelSummary;
foreach($response as $val){
echo $val->name;
}

?>

最佳答案

这应该是您的新代码:

<?php

$xml_file = 'http://dev.api.ean.com/ean-services/rs/hotel/v3/list?minorRev=99&apiKey=ycdydfqdz4w5huxv4psfxs8h&cid=55505&locale=en_US&currencyCode=USD&supplierCacheTolerance=MED_ENHANCED&countryCode=US&city=Dallas&stateProvinceCode=TX&searchRadius=50&numberOfResults=20&arrivalDate=08/31/2014&departureDate=09/15/2014&minRate=100&maxRate=1000&room1=1&numberOfAdults=2';
$content = file_get_contents($xml_file);

$xml = json_decode($content);
//$xml = simplexml_load_file($xml_file);

$response = $xml->HotelListResponse->HotelList->HotelSummary;
foreach($response as $val){
echo $val->name;
}

?>

文件请求以某种方式使用 JSON 文件进行应答。这样解析就可以了。

关于javascript - 尝试使用 simplexml 访问 ean 酒店列表中的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25337071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com