獲取天氣預報json資料的api介面
阿新 • • 發佈:2019-02-18
之前獲取南京未來5天的天氣
http://m.weather.com.cn/data/101190101.html
現在已經更新為
http://m.weather.com.cn/atad/101190101.html
附上我用代理的程式碼,用的是雅虎的代理
$(document).ready(function() { // 天氣 $.getJSON("http://query.yahooapis.com/v1/public/yql", { q: "select * from json where url=\"http://m.weather.com.cn/atad/101190101.html\"", format: "json" }, function(data) { var $content = $("#content") if (data.query.results) { var weatherinfo = data.query.results.weatherinfo; //console.log(weatherinfo); var week = ["星期一","星期二","星期三","星期四","星期五","星期六","星期天","星期一","星期二"]; var week_tomorrow =""; var week_tdat =""; var week_today = weatherinfo.week; var index = $.inArray(week_today,week); week_tomorrow = week[index+1]; week_tdat = week[index+2]; $(".today .location").text(weatherinfo.city); } else { $(".today p:eq(1)").text("獲取資料失敗"); } }); });