我正在使用YQL调用以下URL
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=cbfunc
这将在JSON中返回以下内容
cbfunc({"query":{"count":"1","created":"2009-06-27T11:53:44Z","lang":"en-US","updated":"2009-06-27T11:53:44Z","uri":"http://query.yahooapis.com/v1/yql?q=select+*+from+yahoo.finance.quotes+where+symbol+in+%28%22UTG.L%22%29","diagnostics":{"publiclyCallable":"true","url":[{"execution-time":"468","content":"http://datatables.org/alltables.env"},{"execution-time":"634","content":"http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml"},{"execution-time":"351","content":"http://download.finance.yahoo.com/d/quotes.csv?s=UTG.L&f=aa2bb2b3b4cc1c3c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy"},{"execution-time":"357","content":"select * from csv where url=@url and columns='Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,Change&PercentChange,Change,Commission,ChangeRealtime,AfterHoursChangeRealtime,DividendShare,LastTradeDate,TradeDate,EarningsShare,ErrorIndicationreturnedforsymbolchangedinvalid,EPSEstimateCurrentYear,EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,HoldingsGainPercent,AnnualizedGain,HoldingsGain,HoldingsGainPercentRealtime,HoldingsGainRealtime,MoreInfo,OrderBookRealtime,MarketCapitalization,MarketCapRealtime,EBITDA,ChangeFromYearLow,PercentChangeFromYearLow,LastTradeRealtimeWithTime,ChangePercentRealtime,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime,LastTradePriceOnly,HighLimit,LowLimit,DaysRange,DaysRangeRealtime,FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,ChangeFromFiftydayMovingAverage,PercentChangeFromFiftydayMovingAverage,Name,Notes,Open,PreviousClose,PricePaid,ChangeinPercent,PriceSales,PriceBook,ExDividendDate,PERatio,DividendPayDate,PERatioRealtime,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,Symbol,SharesOwned,ShortRatio,LastTradeTime,TickerTrend,OneyrTargetPrice,Volume,HoldingsValue,HoldingsValueRealtime,YearRange,DaysValueChange,DaysValueChangeRealtime,StockExchange,DividendYield'"}],"javascript":{"instructions-used":"66024"},"user-time":"1537","service-time":"1810","build-version":"1949"},"results":{"quote":{"symbol":"UTG.L","Ask":"129.00","AverageDailyVolume":"354500","Bid":"128.50","AskRealtime":"129.00","BidRealtime":"128.50","BookValue":"0.00","Change_PercentChange":"+7.50 - +6.19%","Change":"+7.50","Commission":null,"ChangeRealtime":"+7.50","AfterHoursChangeRealtime":"N/A - N/A","DividendShare":"0.00","LastTradeDate":"6/26/2009","TradeDate":null,"EarningsShare":"0.00","ErrorIndicationreturnedforsymbolchangedinvalid":"N/A","EPSEstimateCurrentYear":"0.00","EPSEstimateNextYear":"0.00","EPSEstimateNextQuarter":"0.00","DaysLow":"122.00","DaysHigh":"128.75","YearLow":"36.25","YearHigh":"319.75","HoldingsGainPercent":"- - -","AnnualizedGain":"-","HoldingsGain":null,"HoldingsGainPercentRealtime":"N/A - N/A","HoldingsGainRealtime":null,"MoreInfo":"cred","OrderBookRealtime":"N/A","MarketCapitalization":null,"MarketCapRealtime":null,"EBITDA":"0","ChangeFromYearLow":"+92.50","PercentChangeFromYearLow":"+255.17%","LastTradeRealtimeWithTime":"N/A - 128.75<\/b>","ChangePercentRealtime":"N/A - +6.19%","ChangeFromYearHigh":"-191.00","PercebtChangeFromYearHigh":"-59.73%","LastTradeWithTime":"Jun 26 - 128.75<\/b>","LastTradePriceOnly":"128.75","HighLimit":null,"LowLimit":null,"DaysRange":"122.00 - 128.75","DaysRangeRealtime":"N/A - N/A","FiftydayMovingAverage":"125.714","TwoHundreddayMovingAverage":"100.63","ChangeFromTwoHundreddayMovingAverage":"+28.12","PercentChangeFromTwoHundreddayMovingAverage":"+27.94%","ChangeFromFiftydayMovingAverage":"+3.036","PercentChangeFromFiftydayMovingAverage":"+2.42%","Name":"UNITE GROUP","Notes":"-","Open":"122.00","PreviousClose":"121.25","PricePaid":null,"ChangeinPercent":"+6.19%","PriceSales":null,"PriceBook":null,"ExDividendDate":"14-Apr-04","PERatio":null,"DividendPayDate":"13-May-05","PERatioRealtime":null,"PEGRatio":null,"PriceEPSEstimateCurrentYear":null,"PriceEPSEstimateNextYear":null,"Symbol":"UTG.L","SharesOwned":null,"ShortRatio":null,"LastTradeTime":"11:35am","TickerTrend":" --=+++ ","OneyrTargetPrice":null,"Volume":"254927","HoldingsValue":null,"HoldingsValueRealtime":null,"YearRange":"36.25 - 319.75","DaysValueChange":"- - +6.19%","DaysValueChangeRealtime":"N/A - N/A","StockExchange":"London","DividendYield":null,"PercentChange":"+6.19%"}}}});
但我正在努力使用这些数据(我是jQuery和JSON的新手)
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=cbfunc", function(data){
从这个例子只是闪烁受限的URL错误.
任何人的帮助 - 我只是解析数据并打印到屏幕.提前致谢!
你必须用cbfunc
URL 替换你的回调参数(当前)?
.jQuery会自动替换?
正确的回调.
$.getJSON( "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?", // the ? at the end is the key function(data) { // and now do anything you want to with the data (this is just an example) var html = []; // we're using an array and join for IE performance reasons data = data.query; for (var key in data) { html.push([key, ' = ', data[key]].join('')); } $('#debug').html(html.join('
')); } );
更新:这是一个演示:http://jsbin.com/owebo