如何从给定的json中仅获取HotelDetails?

时间:2019-04-10 10:32:32

标签: php jquery json

我只想在表中显示HotelDetails,但前三行未定义,然后在第四行显示数据。

我已经完成了

$.ajax({
          type: "GET",
          url: 'http://localhost/priya/hotel/gethotelinfo.php',
         dataType: "JSON",
          data: {'HotelCode': HotelCode ,'HotelResultIndex': HotelResultIndex},
           success: function (data) {
                    $obj = JSON.parse(data.Get_Hotel_Info_ResultResult, true);
                    //console.log($obj.HotelInfoResult.HotelDetails);
                   $.each($obj.HotelInfoResult, function (i,obj) {      
                        console.log(obj);               
                    $("#hotel").append("<tr><td>" + obj.HotelCode + "</td><td>" + obj.HotelName + "</td><td>" + obj.StarRating + "</td><td>" + obj.HotelURL + "</td><td>" + obj.Description + "</td><td>" + obj.Address + "</td><td>" + obj.CountryName + "</td><td>" + obj.PinCode + "</td><td>" + obj.HotelContactNo + "</td><td>" + obj.FaxNumber + "</td><td>" + obj.Email + "</td><td>" + obj.Latitude + "</td><td>" + obj.Longitude + "</td><td>" + obj.RoomData + "</td><td>" + obj.RoomFacilities + "</td><td>" + obj.Services + "</td><td><a href='roominfo.php?HotelCode="+obj.HotelCode+"&HotelResultIndex="+obj.ResultIndex+"' target='_blank'>Room</a></td></tr>");
               });
           }
        });

这是我的json数据

{"Get_Hotel_Info_ResultResult":"{\"HotelInfoResult\":{\"ResponseStatus\":1,\"Error\":{\"ErrorCode\":0,\"ErrorMessage\":\"\"},\"TraceId\":\"9ca22322-09ed-4ce3-b68d-78a029100f3c\",\"HotelDetails\":{\"HotelCode\":\"1467842\",\"HotelName\":\"The Byke Suraj Plaza\",\"StarRating\":3,\"HotelURL\":null,\"Description\":\"Property Location With a stay at The Byke Suraj Plaza in Thane, you'll be within a 15-minute drive of Sanjay Gandhi National Park and Ovalekar Wadi Butterfly Park.  This hotel is 13.6 mi (21.8 km) from Powai Lake and 15.2 mi (24.5 km) from Kanheri Caves.Rooms Make yourself at home in one of the 122 air-conditioned rooms featuring minibars and flat-screen televisions. Wireless Internet access (surcharge) keeps you connected, and satellite programming is available for your entertainment. Bathrooms have showers and complimentary toiletries. Conveniences include laptop-compatible safes and desks, and housekeeping is provided daily.Amenities Take in the views from a rooftop terrace and make use of amenities such as wireless Internet access (surcharge) and concierge services. Guests can catch a ride to nearby destinations on the area shuttle (surcharge).Dining Enjoy a meal at Farm Fresh or snacks in the coffee shop\\\/café. The hotel also offers 24-hour room service. Quench your thirst with your favorite drink at the bar\\\/lounge. Breakfast is available for a fee.Business, Other Amenities Featured amenities include a business center, express check-in, and complimentary newspapers in the lobby. A roundtrip airport shuttle is provided for a surcharge (available 24 hours), and free valet parking is available onsite.&nbsp;<br\\\/><b>Disclaimer notification: Amenities are subject to availability and may be chargeable as per the hotel policy.<\\\/b>&nbsp; <br \\\/>\",\"Attractions\":[{\"Key\":\"1) \",\"Value\":\"Distances are displayed to the nearest 0.1 mile and kilometer. <br \\\/> <p>Ovalekar Wadi Butterfly Park - 2 km \\\/ 1.3 mi <br \\\/> Sanjay Gandhi National Park - 2.2 km \\\/ 1.3 mi <br \\\/> Tikuji-ni-Wadi - 4 km \\\/ 2.5 mi <br \\\/> Jupiter Hospital - 6.8 km \\\/ 4.2 mi <br \\\/> Viviana Mall - 6.9 km \\\/ 4.3 mi <br \\\/> Masunda Lake - 8.3 km \\\/ 5.2 mi <br \\\/> Korum Mall - 8.4 km \\\/ 5.2 mi <br \\\/> Nirmal Lifestyle Mall - 14.3 km \\\/ 8.9 mi <br \\\/> Dhirubhai Ambani Life Science Centre - 16.7 km \\\/ 10.4 mi <br \\\/> Reliance Corporate Park - 17.7 km \\\/ 11 mi <br \\\/> Indian Institute of Technology Bombay - 21.1 km \\\/ 13.1 mi <br \\\/> Powai Lake - 21.8 km \\\/ 13.6 mi <br \\\/> Hiranandani Business Park - Powai - 21.9 km \\\/ 13.6 mi <br \\\/> Sagar Vihar Garden - 22.1 km \\\/ 13.7 mi <br \\\/> R City Mall - 22.7 km \\\/ 14.1 mi <br \\\/> <\\\/p><p>The nearest major airport is Mumbai (BOM-Chhatrapati Shivaji Intl.) - 31.3 km \\\/ 19.4 mi<\\\/p>\"}],\"HotelFacilities\":[\"24-hour front desk\",\" Accessible bathroom\",\" Airport transportation (surcharge)\",\" Area shuttle (surcharge)\",\" Bar\\\/lounge\",\" Breakfast available (surcharge)\",\" Business center\",\" Coffee shop or café\",\" Concierge services\",\" Dry cleaning\\\/laundry service\",\" Express check-in\",\" Free newspapers in lobby\",\" Free self parking\",\" Free valet parking\",\" Hair salon\",\" In-room accessibility\",\" Laundry facilities\",\" Luggage storage\",\" One meeting room\",\" Restaurant\",\" Roll-in shower\",\" Rooftop terrace\",\" Safe-deposit box at front desk\",\" Smoke-free property\",\" Total number of rooms - 122\",\" Tours\\\/ticket assistance\",\" WiFi (surcharge)\"],\"HotelPolicy\":\"Early check out will attract full cancellation charge unless otherwise specified.|Infant 2 year(s) : Stay for free if using existing bedding. Note, if you need a cot there may be an extra charge.Children 3 - 8 year(s)||\",\"SpecialInstructions\":null,\"HotelPicture\":null,\"Images\":[\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViQft3Fw1qpmR6kk3e3k6P7Q==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViZjgsA99WkKrt92k4Iwg9BA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViQSco4b\\\/CO8tbKvng9OWBxQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVi6wbMBCeXE3FRBCfR6N4jSQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViqBrWYSdg4QxOqGHhjB+7jg==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViiK46a16e7Hx7xHz995J1hQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVif0NiR1vUaLR7Z6uVm15lUA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVicyi0wl9sMTlluzDNPQCFOA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViwEvK8uPBXP5Cfa0kNCbxuQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVif2l7x4lymRrkt7UYdxOd5g==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVirhtOCDApkOSsvPId6i\\\/CeQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVi7RTOw2OascdIckeVcnu7fg==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVigvBX7hR4G3YJ5KUqsUZLfw==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViHmQB4WZOUbzp+kIadTMfwA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViZR+EIkgo6qTy2Or\\\/eCWLeQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBlUnar3TsLeBV97vs454NMyLpnK3AGwA+g==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViO6glJ56m\\\/38RH5nsTle1aA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVi+U2wtqYiHubMYtlNLs6rJw==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViNBkRD2AkODc2lefNbuPOKQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMVie+siDTtE3wFQGCJ3i4zQGQ==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViFjxtMAjV5p0JmFBc5LAoDA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViAfP1Rf1wjLPOFIzD16wMVA==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViLj0+jfW3knW6Bxpm51YFCg==\",\"https:\\\/\\\/api.tbotechnology.in\\\/imageresource.aspx?img=FbrGPTrju5e5v0qrAGTD8pPBsj8\\\/wYA5lPqBj\\\/Ape0\\\/QCIe+Q6uhRW8BLHBV4q8CAf9tiXj7YvBe+TX5\\\/JRvBqLUX4ibZMViYRI7NIu061rgbfUYomXDfQ==\"],\"Address\":\"Ghodbunder Road, Saibaba Vihar Complex, Thane, 400615, India, India\",\"CountryName\":\"India\",\"PinCode\":\"400615\",\"HotelContactNo\":\"+912225971111\",\"FaxNumber\":null,\"Email\":null,\"Latitude\":\"19.26288\",\"Longitude\":\"72.96841\",\"RoomData\":null,\"RoomFacilities\":null,\"Services\":null}}}"}

我想在表格中显示HotelsDetails,我头三行未定义

1 个答案:

答案 0 :(得分:0)

为什么要使用$ obj,只需创建一个var变量并检查其是否有效。

var obj = JSON.parse(data.Get_Hotel_Info_ResultResult, true);