-2

Am trying to call up an json api and iterate the result ,but getting error as

Uncaught TypeError: Cannot use 'in' operator to search for '379741' in {"status":true,"flights":...}

fiddle here 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 here http://jsfiddle.net/au8ahmho/1/

sajanyamaha
  • 3,119
  • 2
  • 26
  • 44

2 Answers2

0

I hope this can help you !

(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>
Anonymous0day
  • 3,012
  • 1
  • 14
  • 16
-1

It depends on how the JSON that is returned is laid out. From the error you posted, it seems you should try flights.flight[flightnumber].

Arham
  • 49
  • 1