2011-02-09 52 views
-1

嗨,我似乎無法讓我的天氣api工作。我正在使用jquery和json,下面是代碼,但我一整天都在盯着它,無法弄清楚我哪裏會出錯。有人能否將目光投向下方,告訴我發生了什麼事? 在此先感謝戴夫。無法使API正常工作。請幫助!

$.get('http://www.worldweatheronline.com/feed/weather.ashx?q=Auckland,New+Zealand&format=json&num_of_days=2&key=7677dba721211420113101', function(data, textStatus) 
    { 
    alert('Status is '+textStatus); 
    alert('JSON data string is: '+data); 

    // this will give us an array of objects 
    var weather = JSON.parse(data); 

    // iterate over public_tweets 
    for(var x=0; x < weather.length; x++) { 
     var twt = weather[x]; 
     var elm = weather.current_condition.temp_C; 
     alert('Current Temp is:'+elm); 
     }); 

回答

1

您的循環沒有終止支架:

$.get('http://www.worldweatheronline.com/feed/weather.ashx?q=Auckland,New+Zealand&format=json&num_of_days=2&key=7677dba721211420113101', function(data, textStatus) 
    { 
     alert('Status is '+textStatus); 
     alert('JSON data string is: '+data); 

     // this will give us an array of objects 
     var weather = JSON.parse(data); 

     // iterate over public_tweets 
     for(var x=0; x < weather.length; x++) 
     { 
      var twt = weather[x]; 
      var elm = weather.current_condition.temp_C; 
      alert('Current Temp is:'+elm); 
     } 
    });