天气地下API天文学

时间:2015-01-26 06:38:41

标签: javascript jquery json

我正在使用Weather Underground API,解析Json并获得结果。 出于某种原因,这并不是为了获得正确的天文学结果:

http://www.wunderground.com/weather/api/d/docs?d=data/astronomy&MR=1

月亮:

电流:

日出:

日落时间:

这是我到目前为止所得到的结果:(已更新)

$.ajax({
    url: "http://api.wunderground.com/api/72df18b7f213607b/astronomy/q/CO/Alamosa.json",
    dataType : "jsonp",
    success : function(parsed_json) {
        var hourly = parsed_json['moon_phase']['current_time']['sunrise']['sunset'];

        for (index in hourly) {
            var newHourlyString = moon_phase[index]['hour'] + ' is ' + current_time[index]['hour'];
            var newHourlyParagraph = $('<p/>').text(newHourlyString);
            $(".astro").append(newHourlyParagraph);
        } 
    }
});     

1 个答案:

答案 0 :(得分:0)

试一试。您的问题中有很多遗漏,但我能够从您关联的视频中提取信息。

您还应该使用asking better questions处理所有必要的详细信息,以获得更好的答案。

&#13;
&#13;
$(document).ready(function() {
  $.ajax({
    url: "http://api.wunderground.com/api/72df18b7f213607b/astronomy/q/CO/Alamosa.json",
    dataType: "jsonp",
    success: function(parsed_json) {
      var moon_phase = parsed_json['moon_phase'];
      var moonData = {};
      moonData['Moon Ill'] = moon_phase['percentIlluminated'] + '%',
        moonData['Moon Age'] = moon_phase['ageOfMoon'],
        moonData['Current Time'] = moon_phase['current_time']['hour'] + ":" + moon_phase['current_time']['minute'],
        moonData['Sunrise'] = moon_phase['sunrise']['hour'] + ":" + moon_phase['sunrise']['minute'],
        moonData['Sunset'] = moon_phase['sunset']['hour'] + ":" + moon_phase['sunset']['minute'];

      for (index in moonData) {
        if (moonData.hasOwnProperty(index)) {
          var newHourlyString = index + ': ' + moonData[index];
          var newHourlyParagraph = $('<p/>').text(newHourlyString);
          $(".astro").append(newHourlyParagraph);
        }
      }
    }
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="astro"></div>
&#13;
&#13;
&#13;