-1

我已经成功地解析了来自Wunderground API的响应,并显示了对某个州和某个城市的“当前”天气状况的响应。这告诉我打电话时外面的确切温度和当前条件。

我现在需要这种能力,但我无法获得 3 天的预测响应与我当前的天气状况响应一起工作。

我的最终结果我想要一个 3 天的预测结果,并且所有这些天都只包含那些天的高温低温。

例子:

  • 第 1 天 - 周一高/低
  • 第 2 天 - 周二高/低
  • 第 3 天 - 周三高/低

从技术上讲,第 01 天就是今天。

如果有人现在可以查看我的脚本并帮助添加缺少的内容,我将不胜感激。

这是我的 JS

    jQuery(document).ready(function($) {

      /* Edit these variables */
      var api = "2ea138a9dd52eabe";
      var state = "TX";
      var city = "Dallas";

      $.ajax({
      url: "http://api.wunderground.com/api/" + api + "/forecast/conditions/q/" + state + "/" + city + ".json",
      dataType : "jsonp",
      success : function(parsed_json) {
          var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
          var icon_json = '<img src ="' + icon_url_json + '" />';
          var temp_json = parsed_json['current_observation']['temp_f'];
            temp_json += "<span>°F</span>";
          var condition_json = parsed_json['current_observation']['weather'];
          var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
          var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
          var location_json = city + ', ' + state;


          var forecastArray = parsed_json['forecast']['txt_forecast']['forecastday'];
                if (forecastArray !== null) {

                    for (var i = 0; i < forecastArray.length; i++) {

                        if (forecastArray[i] !== null) {
                            //use can use this to assing directly to HTML element    
                            console.log(forecastArray[i]['period']);
                            console.log(forecastArray[i]['title']);
                            console.log(forecastArray[i]['fcttext']);

                        }

                    }}

      document.getElementById("weather-icon").innerHTML = icon_json;
      document.getElementById("temp").innerHTML = temp_json;
      document.getElementById("condition").innerHTML = condition_json;  
      document.getElementById("real-feel").innerHTML = real_feel_json;
      document.getElementById("wind").innerHTML = wind_json;
      document.getElementById("location").innerHTML = location_json;

      }
      });
    });

我也把它放在这里,供人们查看它现在的工作情况。http://jsfiddle.net/supasmo/9d5bh/2/

4

1 回答 1

-1

您实际上可以获取接下来 10 天的http://jsfiddle.net/xxk7S/更新。这是更新的代码

 for(var some in parsed_json.forecast.txt_forecast.forecastday){
             console.log("*************");
          $("#nxtDays").append("<b>"+parsed_json.forecast.txt_forecast.forecastday[some].title+" </b> <br />"+
 parsed_json.forecast.txt_forecast.forecastday[some].fcttext+"<br />");                              console.log(parsed_json.forecast.txt_forecast.forecastday[some].title);
      }
于 2014-02-26T05:05:57.293 回答