2015-01-25 2 views
0

Я просто использую API Underground Underground, используя переменные json и parsing. У меня проблема. Если я повторяю код или логику с другим индексом, Json берет последнюю запись. Я пытаюсь повторить ту же запись, но с другим индексом или периодом. Период - это другой день. Как получить два ответа, которые говорят:Weather Underground API Forecast

Прогноз погоды для Понедельника - это несколько облаков время от времени. Низкий -9C. Ветры NNW со скоростью 10-15 км/ч.

Прогноз погоды для Wendesday - это несколько облаков время от времени. Низкий -9C. Ветры NNW со скоростью 10-15 км/ч.

Вот мой код:

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

<!--Use your own API key and city location--> 
<!--1.Embed the WU 3-day forecast summary feature.--> 
$.ajax({ 
    url: "http://api.wunderground.com/api/72df18b7f213607b/forecast/q/CO/Alamosa.json", 
dataType : "jsonp", 
success : function(parsed_json) { 
    var forecast = parsed_json['forecast']['txt_forecast']['forecastday']; 

    for (index in forecast) { 

    $(".three").html('Weather forecast for '+forecast[index]['title']+' is '+forecast[index]['fcttext_metric']); 


     } 
var forecast = parsed_json['forecast']['txt_forecast']['forecastday']; 

    for (index in forecast) { 

    $(".three").html('Weather forecast for '+forecast[2]['title']+' is '+forecast[index]['fcttext_metric']); 


     } 

    } 


}); 


}); //Closes Doc Ready Function 

Вот в документации по Weather Underground http://www.wunderground.com/weather/api/d/docs?d=data/forecast&MR=1

+0

Вы вывесили ваш ключ API. .. Люди могли бы это использовать ... –

ответ

1

Возможно, вы хотите что-то вроде this

$(document).ready(function($){ 
    $.ajax({ 
     url: "http://api.wunderground.com/api/72df18b7f213607b/forecast/q/CO/Alamosa.json", 
     dataType : "jsonp", 
     success : function(parsed_json) { 
      var forecast = parsed_json['forecast']['txt_forecast']['forecastday']; 

      for (index in forecast) { 
       var newForecastString = 'Weather forecast for ' + forecast[index]['title'] + ' is ' + forecast[index]['fcttext_metric']; 
       var newForecastParagraph = $('<p/>').text(newForecastString); 
       $(".three").append(newForecastParagraph); 
      } 
     } 
    }); 
}); 
+0

Не могли бы вы взглянуть на этот http://stackoverflow.com/questions/28145670/weather-underground-api-astronomy – John

Смежные вопросы