簡體   English   中英

jQuery $ getJSON數組未全部顯示

[英]jquery $getJSON array not show all

我有數據json Schedule Flight,但getJSON不會顯示所有信息。 它只是返回null某些數據,並且所有顯示null的數據已經存在。

代碼:

$ (document).ready (function(){

    $.getJSON("/common/v1/airport.json?code=bgw", function(data){

    $.each(data.result.response.airport.pluginData.schedule.arrivals.data, function(){

$("ul").append("<li>"+this.flight.airport.origin.position.region.city+"</li>");

    });

    });

});

我有這個短數據json,數據數組為[25]我只有5個,錯誤為TypeError: this.flight.airport.origin is null

我的數據json鏈接鏈接

至少有一個對象的原點為空。 您可以在將信息添加到列表之前進行簡單的檢查:

$ (document).ready (function(){
    $.getJSON("/common/v1/airport.json?code=bgw", function(data){

    $.each(data.result.response.airport.pluginData.schedule.arrivals.data, function(){

      if (this.flight.airport.origin) {
        $("ul").append("<li>"+this.flight.airport.origin.position.region.city+"</li>");
      }

    });

    });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM