Jquery JSON Get元素何时为日期?

Jquery JSON Get元素何时为日期?,jquery,json,ajax,Jquery,Json,Ajax,我试图使用GET请求并操作一些JSON。但是,结果在JSON中包含一个日期。我能解决这个问题吗?我可以选择之前的信息,但不能选择日期内的数据。我试过2018-06-28,但没有用 "element_count" : 8, "near_earth_objects" : { "2018-06-28" : [ { "links" : { "self" : "https://api.nasa.gov/neo/rest/v1/neo/3251512?api_key=

我试图使用GET请求并操作一些JSON。但是,结果在JSON中包含一个日期。我能解决这个问题吗?我可以选择之前的信息,但不能选择日期内的数据。我试过2018-06-28,但没有用

"element_count" : 8,
  "near_earth_objects" : {
    "2018-06-28" : [ {
      "links" : {
        "self" : "https://api.nasa.gov/neo/rest/v1/neo/3251512?api_key=OFC1FIb06lwdyot0ZN3yRQAQe8pvhK0R1wCx5GAu"
      },
      "neo_reference_id" : "3251512",
      "name" : "(2004 RX10)",
      "nasa_jpl_url" : "http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3251512",
      "absolute_magnitude_h" : 21.3,
      "estimated_diameter" : {
        "kilometers" : {
          "estimated_diameter_min" : 0.1460679643,
          "estimated_diameter_max" : 0.3266178974
        },
        "meters" : {
          "estimated_diameter_min" : 146.0679642714,
          "estimated_diameter_max" : 326.6178974458
        },
        "miles" : {
          "estimated_diameter_min" : 0.090762397,
          "estimated_diameter_max" : 0.2029508896
        },
        "feet" : {
          "estimated_diameter_min" : 479.2256199,
          "estimated_diameter_max" : 1071.581062656
        }
      },
      "is_potentially_hazardous_asteroid" : false,
      "close_approach_data" : [ {
        "close_approach_date" : "2018-06-28",
        "epoch_date_close_approach" : 1530169200000,
        "relative_velocity" : {
          "kilometers_per_second" : "13.0790754914",
          "kilometers_per_hour" : "47084.6717691282",
          "miles_per_hour" : "29256.5839667675"
        },
        "miss_distance" : {
          "astronomical" : "0.1504186394",
          "lunar" : "58.5128517151",
          "kilometers" : "22502308",
          "miles" : "13982286"
        },
        "orbiting_body" : "Earth"
      } ]
    },
以下是我到目前为止所做的尝试:

jQuery.getJSON("neo-current.json", function(data) {  
    $("#neo").html(data.element_count+" NEO(s)");
    var date = "2018-06-28";
    $.each(data, function(index, i) {
        console.log(i.near_earth_objects.date.name);
    });
});
应该是:

console.logi.near\u earth\u objects[date].name

找到了解决办法

jQuery(document).ready(function($) {
    var hazardous = '0';
    jQuery.getJSON("neo-current.json", function(data) {  
        $("#neo").html(data.element_count+" NEO(s)");
        var date = Object.keys(data.near_earth_objects)[0];
        $.each(data.near_earth_objects[date], function(index, i) {
            console.log(i.name+" "+i.is_potentially_hazardous_asteroid);
            if (i.is_potentially_hazardous_asteroid == true) {
                hazardous ++
            } else {
                //Do Nothing
            }
        });
        $("#hazardous-neo").html(hazardous+" NEO(S)");
    });
});

不幸的是,这导致:Uncaught TypeError:无法读取未定义的属性“2018-06-28”。这意味着您的循环/迭代在某个地方失败,看起来i.near_earth_对象未定义。通过检查i.near_earth_objects的值,甚至是循环中的i,尝试缩小根本原因。我可以让它与:$.eachdata.near_earth_objects[2018-06-28],functionindex,i{console.logi.name;};但是,试图让它自动设置JSON中的日期,即data.near_earth_objects[1]之类的东西。所以我不必使用矩来添加另一个依赖项。如果是这样,您可以使用。。。在as中。例如:对于i.近地天体中的let日期。请注意顺序,这是一个通过对象键的循环,它不应该像您从JSON中看到的那样维护顺序