以下是我的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
之下,但无法这样做。我的代码怎么了?
答案 0 :(得分:2)
您正在访问错误的媒体资源:
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>
&#13;
答案 1 :(得分:0)
您必须parsed_json["history"]["dailysummary"][0]["maxtempi"]
访问maxtempi
。
jQuery(document).ready(function($) {
$.ajax({
url :"http://api.wunderground.com/api/f40719f4c7835e02/history_20060405/q/CA/San_Francisco.json",
dataType : "json",
success : function(parsed_json) {
var maxtempi = parsed_json["history"]["dailysummary"][0]["maxtempi"];
//var temp_f = parsed_json['dailysummary']['maxtempi'];
alert("Maxtempi is " + maxtempi);
}
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
&#13;