我有以下JSON位于../ JSON / addresses.json:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<air:LowFareSearchRsp TransactionId="6F965E450A076478B86F876C892DCB3B" ResponseTime="42833" DistanceUnits="MI" CurrencyType="LKR" xmlns:air="http://www.travelport.com/schema/air_v25_0" xmlns:common_v25_0="http://www.travelport.com/schema/common_v25_0">
<common_v25_0:ResponseMessage Code="2027" Type="Warning" ProviderCode="1P">Requested date is out of provider supported date range. Results may have been returned with other dates.</common_v25_0:ResponseMessage>
<air:FlightDetailsList>
<air:FlightDetails Key="/f+YonrXRQKE6/ePot1icg==" Origin="CMB" Destination="BKK" DepartureTime="2015-11-14T01:40:00.000+05:30" ArrivalTime="2015-11-14T06:35:00.000+07:00" FlightTime="205" TravelTime="205" Distance="1485" Equipment="320"/>
<air:FlightDetails Key="RZaPXzrqT7aBia5Rv5HDSw==" Origin="CMB" Destination="BKK" DepartureTime="2015-11-14T07:20:00.000+05:30" ArrivalTime="2015-11-14T12:15:00.000+07:00" FlightTime="205" TravelTime="205" Distance="1485" Equipment="332"/>
<air:FlightDetails Key="jZVn/oAjTOGbbPrq7V0WXQ==" Origin="CMB" Destination="KUL" DepartureTime="2015-11-14T00:40:00.000+05:30" ArrivalTime="2015-11-14T06:55:00.000+08:00" FlightTime="225" TravelTime="225" Distance="1530" Equipment="320" DestinationTerminal="M"/>
<air:FlightDetails Key="47Vb5TYpQpGruHS0FlMuEA==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T13:05:00.000+08:00" ArrivalTime="2015-11-14T14:10:00.000+07:00" FlightTime="125" TravelTime="495" Distance="759" Equipment="787" OriginTerminal="M"/>
<air:FlightDetails Key="S4cPtkw/TiWUazgonAmzrw==" Origin="CMB" Destination="KUL" DepartureTime="2015-11-14T07:30:00.000+05:30" ArrivalTime="2015-11-14T13:45:00.000+08:00" FlightTime="225" TravelTime="225" Distance="1530" Equipment="321" DestinationTerminal="M"/>
<air:FlightDetails Key="5hrw3GrAQ929uDyp8ROe7A==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T21:00:00.000+08:00" ArrivalTime="2015-11-14T22:05:00.000+07:00" FlightTime="125" TravelTime="560" Distance="759" Equipment="787" OriginTerminal="M"/>
<air:FlightDetails Key="9W5gjL57STePdYm7f6DPIA==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T15:15:00.000+08:00" ArrivalTime=
如何检索&#39; id&#39;使用 $。getJSON 时的属性?我尝试了以下代码,但控制台返回&#39; undefined&#39;错误:
[
{
"id":"Cheonan2",
"Field1": "96, 3Gongdan1-ro",
"Field2": "Seobuk-gu, Cheonan-si",
"Field3": "Chungcheongnam-do, 31093, Korea",
"Field4": "",
"Field1K": "31093 충청남도 천안시",
"Field2K": "서북구 3공단1로 96",
"Field3K": "",
"Field4K": ""
}
]
答案 0 :(得分:3)
如果我们假设您的JSON URL返回JSONAddress
数组,那么您应该写:
$.getJSON("../JSON/addresses.json",function(JSONAddress){
console.log(JSONAddress[0].id);
});