我试图调用json api并迭代结果,但得到错误
未捕获的TypeError:无法在'中使用'运营商搜索' 379741'在 {"状态":真,"航班" ...}
在这里摆弄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);
//});
});
})();
答案 0 :(得分:0)
我希望这可以帮到你!
(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>
答案 1 :(得分:-1)
这取决于返回的JSON的布局方式。根据您发布的错误,您似乎应该尝试flights.flight[flightnumber]
。