开发者

Not getting a complete conversion of Yahoo's weather API - XML to JSON

I'm new to JavaScript but was hoping to use the JSON output of yahoo's weather api to do some cool things with my website. The problem is that for some reason I'm not getting a full pull of the JSON data and I'm not sure why. My JSON should start at "channel" but it instead starts at "item". If you follow this link http://weather.yahooapis.com/forecastrss?p=USOH0293&u=c you should be able to see what the complete (pre JSON) XML looks like.

Here's the JavaScript I'm using (it does successfully add the current condition to the body tag)... Any help would be greatly appreciated.

    $(document).ready(function() {  

    $.YQL = function(query, callback) {
        var encodedQuery = encodeURIComponent(query.toLowerCase()),
            url = 'http://query.yahooapis.com/v1/public/yql?q='
                + encodedQuery + '&format=json&callback=?';
        $.getJSON(url, callback);
    };
    $.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?p=USOH0293&u=c'",function(data){
                var w=data.query.results.item;
         开发者_如何学Go       var class=w.condition.text;
                var encodedclass = class.replace(/\s+/g, '-').toLowerCase();
                $('body').addClass(encodedclass);
           });
    });


Have a look on

http://jsfiddle.net/x3rmr/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜