JSON 数据迭代
JSON data iteration
我正在尝试调用 json api 并迭代结果,但出现错误
Uncaught TypeError: Cannot use 'in' operator to search for '379741' in
{"status":true,"flights":...}
fiddle 这里 http://jsfiddle.net/au8ahmho/1/
(function () {
var flickerAPI = 'http://whateverorigin.org/get?url=' + 'http://www.dubaiairports.ae/FIDS_cache/arrivals_today_all.json' + '&callback=?';
$.getJSON(flickerAPI, {
format: "json"
})
.done(function (data) {
//$.each(data.contents, function (flights) {
// alert(flights.flightnumber);
//});
});
})();
fiddle 这里 http://jsfiddle.net/au8ahmho/1/
这取决于返回的 JSON 是如何布局的。从您发布的错误来看,您似乎应该尝试 flights.flight[flightnumber]
.
希望对您有所帮助!
(function () {
var flickerAPI = 'http://whateverorigin.org/get?url=' + 'http://www.dubaiairports.ae/FIDS_cache/arrivals_today_all.json' + '&callback=?';
$.getJSON(flickerAPI, {
format: "json" ,
beforeSend : function(){
$('#el').html(' waiting a response from http://whateverorigin.org/');
}
})
.done(function (data) {
console.log(JSON.parse(data.contents) );
var ff = JSON.parse(data.contents) ;
var numbers = ff.flights.map(function(flight){
return flight.flightNumber;
});
$('#el').html( numbers.join('<br>') );
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='el'></div>
我正在尝试调用 json api 并迭代结果,但出现错误
Uncaught TypeError: Cannot use 'in' operator to search for '379741' in {"status":true,"flights":...}
fiddle 这里 http://jsfiddle.net/au8ahmho/1/
(function () {
var flickerAPI = 'http://whateverorigin.org/get?url=' + 'http://www.dubaiairports.ae/FIDS_cache/arrivals_today_all.json' + '&callback=?';
$.getJSON(flickerAPI, {
format: "json"
})
.done(function (data) {
//$.each(data.contents, function (flights) {
// alert(flights.flightnumber);
//});
});
})();
fiddle 这里 http://jsfiddle.net/au8ahmho/1/
这取决于返回的 JSON 是如何布局的。从您发布的错误来看,您似乎应该尝试 flights.flight[flightnumber]
.
希望对您有所帮助!
(function () {
var flickerAPI = 'http://whateverorigin.org/get?url=' + 'http://www.dubaiairports.ae/FIDS_cache/arrivals_today_all.json' + '&callback=?';
$.getJSON(flickerAPI, {
format: "json" ,
beforeSend : function(){
$('#el').html(' waiting a response from http://whateverorigin.org/');
}
})
.done(function (data) {
console.log(JSON.parse(data.contents) );
var ff = JSON.parse(data.contents) ;
var numbers = ff.flights.map(function(flight){
return flight.flightNumber;
});
$('#el').html( numbers.join('<br>') );
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='el'></div>