1
我正在使用weatherunderground api,并且我只想访问今天的预测。我通常使用parsed_json [] [],直到我得到我需要的变量,但在这种情况下,有一个数组。这里是我的代码:如何访问json API中的某个字符串变量?
function findWeather() {
jQuery(document).ready(function($) {
$.ajax({
url : "http://api.wunderground.com/api/c531e176f43b999d/forecast/q/CT/Old_Greenwich.json",
dataType : "jsonp",
success : function(parsed_json) {
var forecasts = parsed_json['forecast']['txt_forecast']['forecastday: 0']['fcttext'];
var forecastString = "The weather is" + forecasts + "."
speak(" test" + forecastString);
}
});
});
}
function speak(x) {
var msg = new SpeechSynthesisUtterance(x);
window.speechSynthesis.speak(msg);
}
如果你去的URL,你会看到整个工作表和我试图访问的信息。我一直试图解决这个问题几个小时,并找不到任何帮助谷歌。