2016-10-11 4 views
0

У меня есть этот API https://api.nasa.gov/neo/rest/v1/feed?start_date=2015-09-07&end_date=2015-09-08&detailed=false&api_key=DEMO_KEYБурение через данные JSon

У меня возникли проблемы бурения до данных:

Как я могу получить его, чтобы дать мне только те данные, где is_potentially_hazardous_asteroid ": истинный Использование JQuery Ajax и это дает мне неопределенными ...

$(document).ready (function() { 
    var url = "https://api.nasa.gov/neo/rest/v1/feed?start_date=2015-09-07&end_date=2015-09-08&api_key=DEMO_KEY"; 
    $.ajax({ 
     url: url, 
     success: function(data){ 
      console.log(data.near_earth_objects.2015-09-08); 
     } 
    }); 
}); 

ответ

0

Попробуйте вместо этого:

$(document).ready (function() { 
    var url = "https://api.nasa.gov/neo/rest/v1/feed?start_date=2015-09-07&end_date=2015-09-08&api_key=DEMO_KEY"; 
    $.ajax({ 
     url: url, 
     success: function (data) { 
      // you can't use dot syntax with numbers: 
      // console.log (thing.123); 
      // try this instead: 
      var neos = data.near_earth_objects['2015-09-08']; 
      // and to find the hazardous asteroids: 
      var hazardous_neos = neos.filter (function (d) { 
       // return true to add d to the array returned from filter() 
       // return false to NOT add d to the array from filter() 

       // if we want hazardous asteroids then 
       // since is_potentially_hazardous_asteroid is a 
       // boolean where true means it's hazardous then 
       // we can simply return its value 
       return d.is_potentially_hazardous_asteroid; 

       // if we want NON-hazardous asteroids we can do: 
       //return d.is_potentially_hazardous_asteroid == false; 
      }); 

      console.log (hazardous_neos); 
     } 
    }); 
}); 
+0

Спасибо, это сработало! – SakoBu

+0

Затем, пожалуйста, отметьте его как «принятый», чтобы другие могли легко найти ответ, если у них есть аналогичная проблема. – erapert

+0

Как проверить/отфильтровать ложь? – SakoBu