0

我在 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&currencyCode=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
                                            )

                                    )

                            )

                    )

            )

    )

  )
4

1 回答 1

0

你在一个变量中得到了响应,然后像这样使用每个变量

例如,您的变量是$obj指然后将其作为

foreach ($obj['HotelListResponse']['HotelList']['HotelSummary'] as $HOTEL) { "你的 html 代码在这里例如:如果我需要酒店的名称 } 像这样

并在最后关闭 for each

<?php }?>

希望这可以帮助

于 2014-03-01T07:07:53.147 回答