我是API调用和学习阶段的新手。我正在使用PHP的Expedia开发API。我成功获得响应转储,我可以在页面上显示转储。但是有人可以告诉我,我需要做什么来转换/解析API响应并转换成网页。 我真的很难理解我如何使用该输出转换成html显示为正常的假期预订或酒店网站。为了更好地理解我正在粘贴我从Expedia收到的回复。请指教
[HotelSummary] => SimpleXMLElement Object
(
[@attributes] => Array
(
[order] => 0
)
[hotelId] => 425669
[name] => Hôtel Luxor
[address1] => 24, Rue Ernest Renan
[city] => Issy-les-Moulineaux
[postalCode] => 92130
[countryCode] => FR
[airportCode] => SimpleXMLElement Object
(
[0] =>
)
[supplierType] => E
[propertyCategory] => 1
[hotelRating] => 1.0
[confidenceRating] => 52
[amenityMask] => 0
[tripAdvisorRating] => 1.5
[locationDescription] => Near Paris Expo Porte de Versailles
[shortDescription] => <p><b>Location. </b> <br />Hôtel Luxor is located in Issy-les-Moulineaux's Gare Montparnasse - Porte de Versailles neighborhood, close to Paris Expo Porte de Versailles, Eiffel Tower, and Stade de
[highRate] => 43.76
[lowRate] => 43.76
[rateCurrencyCode] => EUR
[latitude] => 48.82882
[longitude] => 2.28239
[proximityDistance] => 1.7304468
[proximityUnit] => MI
[hotelInDestination] => true
[thumbNailUrl] => /hotels/6000000/5670000/5669900/5669864/5669864_4_t.jpg
[deepLink] => http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=425669&mode=2&numberOfRooms=1&room-0-adult-total=1&room-0-child-total=0&arrivalMonth=8&arrivalDay=17&departureMonth=8&departureDay=18&showInfo=true&locale=en_US¤cyCode=EUR
[RoomRateDetailsList] => SimpleXMLElement Object
(
[RoomRateDetails] => SimpleXMLElement Object
(
[roomTypeCode] => 200245723
[rateCode] => 201427808
[maxRoomOccupancy] => 2
[quotedRoomOccupancy] => 1
[minGuestAge] => 0
[roomDescription] => Moderate - shared bathroom
[currentAllotment] => 10
[propertyAvailable] => true
[propertyRestricted] => false
[expediaPropertyId] => 5669864
[rateKey] => 3f0bfd6a-d45b-496d-a986-eb8aade2b3e8
[RateInfo] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rateChange] => false
[promo] => false
[priceBreakdown] => true
)
[ChargeableRateInfo] => SimpleXMLElement Object
(
[@attributes] => Array
(
[total] => 47.0
[surchargeTotal] => 3.24
[nightlyRateTotal] => 43.76
[maxNightlyRate] => 43.76
[currencyCode] => EUR
[commissionableUsdTotal] => 57.72
[averageRate] => 43.76
[averageBaseRate] => 43.76
)
[NightlyRatesPerRoom] => SimpleXMLElement Object
(
[@attributes] => Array
(
[size] => 1
)
[NightlyRate] => SimpleXMLElement Object
(
[@attributes] => Array
(
[promo] => false
[rate] => 43.76
[baseRate] => 43.76
)
)
)
[Surcharges] => SimpleXMLElement Object
(
[@attributes] => Array
(
[size] => 1
)
[Surcharge] => SimpleXMLElement Object
(
[@attributes] => Array
(
[amount] => 3.24
[type] => TaxAndServiceFee
)
)
)
)
)
[ValueAdds] => SimpleXMLElement Object
(
[@attributes] => Array
(
[size] => 1
)
[ValueAdd] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2048
)
[description] => Free Wireless Internet
)
)
)
)
)
)
)
答案 0 :(得分:0)
你在变量中得到了响应,然后像这样使用每个
例如,此处的变量为$obj
表示将其设为
foreach($ obj ['HotelListResponse'] ['HotelList'] ['HotelSummary'] as $ HOTEL){“你的html代码在这里e g:如果我需要这样的酒店名称}
并在结尾处关闭每个
<?php }?>
希望这会有所帮助