以下是我的JavaScript代码:

jQuery(document).ready(function($) {
    $.ajax({
         url: "http://api.wunderground.com/api/f40719f4c7835e02/history_20060405/q/CA/San_Francisco.json",
        dataType : "jsonp",
        success : function(parsed_json) {
            var maxtempi = parsed_json['dailysummary']['maxtempi'];
            //var temp_f = parsed_json['dailysummary']['maxtempi'];
            alert("Maxtempi is" + maxtempi);
        }
    });
});


我正在尝试在maxtempi下获取dailysummary,但是无法这样做。我的代码有什么问题?

最佳答案

您正在访问错误的属性:



jQuery(document).ready(function($) {
  $.ajax({
    url: "https://api.wunderground.com/api/f40719f4c7835e02/history_20060405/q/CA/San_Francisco.json",
    dataType: "jsonp",
    success: function(parsed_json) {
      console.log(parsed_json);
      var maxtempi = parsed_json.history.dailysummary[0].maxtempi;
      //var temp_f = parsed_json['dailysummary']['maxtempi'];
      alert("Maxtempi is" + maxtempi);
    }
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

09-30 20:48