如何使用Jquery读取此JSON?让我们说我想用“引用”对象获取所有数据。非常感谢!
cbfunc({
"query": {
"count": "4",
"created": "2010-12-01T15:21:42Z",
"lang": "en-US",
"diagnostics": {
"publiclyCallable": "true",
"url": [{
"execution-time": "3",
"proxy": "DEFAULT",
"content": "http://datatables.org/alltables.env"
},
{
"execution-time": "1",
"proxy": "DEFAULT",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml"
},
{
"execution-time": "12",
"proxy": "DEFAULT",
"content": "http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=YHOO,AAPL,GOOG,MSFT"
},
{
"execution-time": "18",
"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": {
"execution-time": "71",
"instructions-used": "278867",
"table-name": "yahoo.finance.quotes"
},
"user-time": "92",
"service-time": "16",
"build-version": "9962"
},
"results": {
"quote": [{
"symbol": "YHOO",
"Ask": "16.21",
"AverageDailyVolume": "24744700",
"Bid": "16.20",
"AskRealtime": "16.21",
"BidRealtime": "16.20",
"BookValue": "9.277",
"Change_PercentChange": "+0.393 - +2.48%",
"Change": "+0.393",
"Commission": null,
"ChangeRealtime": "+0.393",
"AfterHoursChangeRealtime": "N/A - N/A",
"DividendShare": "0.00",
"LastTradeDate": "12/1/2010",
"TradeDate": null,
"EarningsShare": "0.77",
"ErrorIndicationreturnedforsymbolchangedinvalid": "N/A",
"EPSEstimateCurrentYear": "0.86",
"EPSEstimateNextYear": "0.79",
"EPSEstimateNextQuarter": "0.19",
"DaysLow": null,
"DaysHigh": "16.23",
"YearLow": "12.94",
"YearHigh": "19.12",
"HoldingsGainPercent": "- - -",
"AnnualizedGain": "-",
"HoldingsGain": null,
"HoldingsGainPercentRealtime": "N/A - N/A",
"HoldingsGainRealtime": null,
"MoreInfo": "cnsprmiIed",
"OrderBookRealtime": "N/A",
"MarketCapitalization": "21.127B",
"MarketCapRealtime": null,
"EBITDA": "1.399B",
"ChangeFromYearLow": "+3.268",
"PercentChangeFromYearLow": "+25.26%",
"LastTradeRealtimeWithTime": "N/A - <b>16.208</b>",
"ChangePercentRealtime": "N/A - +2.48%",
"ChangeFromYearHigh": "-2.912",
"PercebtChangeFromYearHigh": "-15.23%",
"LastTradeWithTime": "10:05am - <b>16.208</b>",
"LastTradePriceOnly": "16.208",
"HighLimit": null,
"LowLimit": null,
"DaysRange": "N/A - 16.23",
"DaysRangeRealtime": "N/A - N/A",
"FiftydayMovingAverage": "16.1875",
"TwoHundreddayMovingAverage": "14.9097",
"ChangeFromTwoHundreddayMovingAverage": "+1.2983",
"PercentChangeFromTwoHundreddayMovingAverage": "+8.71%",
"ChangeFromFiftydayMovingAverage": "+0.0205",
"PercentChangeFromFiftydayMovingAverage": "+0.13%",
"Name": "Yahoo! Inc.",
"Notes": "-",
"Open": "16.04",
"PreviousClose": "15.815",
"PricePaid": null,
"ChangeinPercent": "+2.48%",
"PriceSales": "3.16",
"PriceBook": "1.70",
"ExDividendDate": "12-May-04",
"PERatio": "20.54",
"DividendPayDate": "N/A",
"PERatioRealtime": null,
"PEGRatio": "1.40",
"PriceEPSEstimateCurrentYear": "18.39",
"PriceEPSEstimateNextYear": "20.02",
"Symbol": "YHOO",
"SharesOwned": null,
"ShortRatio": "2.40",
"LastTradeTime": "10:05am",
"TickerTrend": " ++--++ ",
"OneyrTargetPrice": "18.07",
"Volume": "2751507",
"HoldingsValue": null,
"HoldingsValueRealtime": null,
"YearRange": "12.94 - 19.12",
"DaysValueChange": "- - +2.48%",
"DaysValueChangeRealtime": "N/A - N/A",
"StockExchange": "NasdaqNM",
"DividendYield": null,
"PercentChange": "+2.48%"
},
{
"symbol": "AAPL",
"Ask": "316.04",
"AverageDailyVolume": "18898400",
"Bid": "316.00",
"AskRealtime": "316.04",
"BidRealtime": "316.00",
"BookValue": "52.175",
"Change_PercentChange": "+4.87 - +1.57%",
"Change": "+4.87",
"Commission": null,
"ChangeRealtime": "+4.87",
"AfterHoursChangeRealtime": "N/A - N/A",
"DividendShare": "0.00",
"LastTradeDate": "12/1/2010",
"TradeDate": null,
"EarningsShare": "15.154",
"ErrorIndicationreturnedforsymbolchangedinvalid": "N/A",
"EPSEstimateCurrentYear": "18.97",
"EPSEstimateNextYear": "22.06",
"EPSEstimateNextQuarter": "4.22",
"DaysLow": "315.00",
"DaysHigh": "316.50",
"YearLow": "188.68",
"YearHigh": "321.30",
"HoldingsGainPercent": "- - -",
"AnnualizedGain": "-",
"HoldingsGain": null,
"HoldingsGainPercentRealtime": "N/A - N/A",
"HoldingsGainRealtime": null,
"MoreInfo": "cnsprmiIed",
"OrderBookRealtime": "N/A",
"MarketCapitalization": "289.9B",
"MarketCapRealtime": null,
"EBITDA": "19.364B",
"ChangeFromYearLow": "+127.34",
"PercentChangeFromYearLow": "+67.49%",
"LastTradeRealtimeWithTime": "N/A - <b>316.02</b>",
"ChangePercentRealtime": "N/A - +1.57%",
"ChangeFromYearHigh": "-5.28",
"PercebtChangeFromYearHigh": "-1.64%",
"LastTradeWithTime": "10:05am - <b>316.02</b>",
"LastTradePriceOnly": "316.02",
"HighLimit": null,
"LowLimit": null,
"DaysRange": "315.00 - 316.50",
"DaysRangeRealtime": "N/A - N/A",
"FiftydayMovingAverage": "309.455",
"TwoHundreddayMovingAverage": "273.218",
"ChangeFromTwoHundreddayMovingAverage": "+42.802",
"PercentChangeFromTwoHundreddayMovingAverage": "+15.67%",
"ChangeFromFiftydayMovingAverage": "+6.565",
"PercentChangeFromFiftydayMovingAverage": "+2.12%",
"Name": "Apple Inc.",
"Notes": "-",
"Open": "315.665",
"PreviousClose": "311.15",
"PricePaid": null,
"ChangeinPercent": "+1.57%",
"PriceSales": "4.38",
"PriceBook": "5.96",
"ExDividendDate": "21-Nov-95",
"PERatio": "20.53",
"DividendPayDate": "N/A",
"PERatioRealtime": null,
"PEGRatio": "0.83",
"PriceEPSEstimateCurrentYear": "16.40",
"PriceEPSEstimateNextYear": "14.10",
"Symbol": "AAPL",
"SharesOwned": null,
"ShortRatio": "0.50",
"LastTradeTime": "10:05am",
"TickerTrend": " -=+-+- ",
"OneyrTargetPrice": "365.38",
"Volume": "3679572",
"HoldingsValue": null,
"HoldingsValueRealtime": null,
"YearRange": "188.68 - 321.30",
"DaysValueChange": "- - +1.57%",
"DaysValueChangeRealtime": "N/A - N/A",
"StockExchange": "NasdaqNM",
"DividendYield": null,
"PercentChange": "+1.57%"
},
{
"symbol": "GOOG",
"Ask": "568.94",
"AverageDailyVolume": "3086980",
"Bid": "568.55",
"AskRealtime": "568.94",
"BidRealtime": "568.55",
"BookValue": "135.606",
"Change_PercentChange": "+13.208 - +2.38%",
"Change": "+13.208",
"Commission": null,
"ChangeRealtime": "+13.208",
"AfterHoursChangeRealtime": "N/A - N/A",
"DividendShare": "0.00",
"LastTradeDate": "12/1/2010",
"TradeDate": null,
"EarningsShare": "24.616",
"ErrorIndicationreturnedforsymbolchangedinvalid": "N/A",
"EPSEstimateCurrentYear": "28.79",
"EPSEstimateNextYear": "33.37",
"EPSEstimateNextQuarter": "7.92",
"DaysLow": "562.40",
"DaysHigh": "570.43",
"YearLow": "433.63",
"YearHigh": "630.85",
"HoldingsGainPercent": "- - -",
"AnnualizedGain": "-",
"HoldingsGain": null,
"HoldingsGainPercentRealtime": "N/A - N/A",
"HoldingsGainRealtime": null,
"MoreInfo": "cnprmiIed",
"OrderBookRealtime": "N/A",
"MarketCapitalization": "181.9B",
"MarketCapRealtime": null,
"EBITDA": "11.260B",
"ChangeFromYearLow": "+135.288",
"PercentChangeFromYearLow": "+31.20%",
"LastTradeRealtimeWithTime": "N/A - <b>568.918</b>",
"ChangePercentRealtime": "N/A - +2.38%",
"ChangeFromYearHigh": "-61.9319",
"PercebtChangeFromYearHigh": "-9.82%",
"LastTradeWithTime": "10:05am - <b>568.918</b>",
"LastTradePriceOnly": "568.918",
"HighLimit": null,
"LowLimit": null,
"DaysRange": "562.40 - 570.43",
"DaysRangeRealtime": "N/A - N/A",
"FiftydayMovingAverage": "598.612",
"TwoHundreddayMovingAverage": "515.244",
"ChangeFromTwoHundreddayMovingAverage": "+53.674",
"PercentChangeFromTwoHundreddayMovingAverage": "+10.42%",
"ChangeFromFiftydayMovingAverage": "-29.694",
"PercentChangeFromFiftydayMovingAverage": "-4.96%",
"Name": "Google Inc.",
"Notes": "-",
"Open": null,
"PreviousClose": "555.71",
"PricePaid": null,
"ChangeinPercent": "+2.38%",
"PriceSales": "6.45",
"PriceBook": "4.10",
"ExDividendDate": "N/A",
"PERatio": "22.58",
"DividendPayDate": "N/A",
"PERatioRealtime": null,
"PEGRatio": "1.17",
"PriceEPSEstimateCurrentYear": "19.30",
"PriceEPSEstimateNextYear": "16.65",
"Symbol": "GOOG",
"SharesOwned": null,
"ShortRatio": "1.30",
"LastTradeTime": "10:05am",
"TickerTrend": " =---+= ",
"OneyrTargetPrice": "669.13",
"Volume": "1279039",
"HoldingsValue": null,
"HoldingsValueRealtime": null,
"YearRange": "433.63 - 630.85",
"DaysValueChange": "- - +2.38%",
"DaysValueChangeRealtime": "N/A - N/A",
"StockExchange": "NasdaqNM",
"DividendYield": null,
"PercentChange": "+2.38%"
},
{
"symbol": "MSFT",
"Ask": "25.93",
"AverageDailyVolume": "61957100",
"Bid": "25.92",
"AskRealtime": "25.93",
"BidRealtime": "25.92",
"BookValue": "5.483",
"Change_PercentChange": "+0.6625 - +2.62%",
"Change": "+0.6625",
"Commission": null,
"ChangeRealtime": "+0.6625",
"AfterHoursChangeRealtime": "N/A - N/A",
"DividendShare": "0.55",
"LastTradeDate": "12/1/2010",
"TradeDate": null,
"EarningsShare": "2.326",
"ErrorIndicationreturnedforsymbolchangedinvalid": "N/A",
"EPSEstimateCurrentYear": "2.46",
"EPSEstimateNextYear": "2.68",
"EPSEstimateNextQuarter": "0.56",
"DaysLow": "25.56",
"DaysHigh": "25.92",
"YearLow": "22.73",
"YearHigh": "31.58",
"HoldingsGainPercent": "- - -",
"AnnualizedGain": "-",
"HoldingsGain": null,
"HoldingsGainPercentRealtime": "N/A - N/A",
"HoldingsGainRealtime": null,
"MoreInfo": "cnsprmiIed",
"OrderBookRealtime": "N/A",
"MarketCapitalization": "221.8B",
"MarketCapRealtime": null,
"EBITDA": "29.879B",
"ChangeFromYearLow": "+3.19",
"PercentChangeFromYearLow": "+14.03%",
"LastTradeRealtimeWithTime": "N/A - <b>25.92</b>",
"ChangePercentRealtime": "N/A - +2.62%",
"ChangeFromYearHigh": "-5.66",
"PercebtChangeFromYearHigh": "-17.92%",
"LastTradeWithTime": "10:05am - <b>25.92</b>",
"LastTradePriceOnly": "25.92",
"HighLimit": null,
"LowLimit": null,
"DaysRange": "25.56 - 25.92",
"DaysRangeRealtime": "N/A - N/A",
"FiftydayMovingAverage": "25.9114",
"TwoHundreddayMovingAverage": "25.3427",
"ChangeFromTwoHundreddayMovingAverage": "+0.5773",
"PercentChangeFromTwoHundreddayMovingAverage": "+2.28%",
"ChangeFromFiftydayMovingAverage": "+0.0086",
"PercentChangeFromFiftydayMovingAverage": "+0.03%",
"Name": "Microsoft Corpora",
"Notes": "-",
"Open": "25.58",
"PreviousClose": "25.2575",
"PricePaid": null,
"ChangeinPercent": "+2.62%",
"PriceSales": "3.29",
"PriceBook": "4.61",
"ExDividendDate": "Nov 16",
"PERatio": "10.86",
"DividendPayDate": "Dec 9",
"PERatioRealtime": null,
"PEGRatio": "1.04",
"PriceEPSEstimateCurrentYear": "10.27",
"PriceEPSEstimateNextYear": "9.42",
"Symbol": "MSFT",
"SharesOwned": null,
"ShortRatio": "1.10",
"LastTradeTime": "10:05am",
"TickerTrend": " +=-=== ",
"OneyrTargetPrice": "32.53",
"Volume": "12466320",
"HoldingsValue": null,
"HoldingsValueRealtime": null,
"YearRange": "22.73 - 31.58",
"DaysValueChange": "- - +2.62%",
"DaysValueChangeRealtime": "N/A - N/A",
"StockExchange": "NasdaqNM",
"DividendYield": "2.18",
"PercentChange": "+2.62%"
}]
}
}
});
答案 0 :(得分:2)
你所拥有的不是JSON。它是带填充的JSON。您必须删除“cbfunc(”和结尾“)”才能将其解析为JSON。然后你可以使用:
var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.query.results.quote );
获取一个对象。
您还可以声明一个名为function cbfunc(o){}
的函数,然后在您的字符串周围执行eval()
,但这可能不是最安全的方法。 :)
答案 1 :(得分:0)
jquery有一个方法
答案 2 :(得分:0)
您发布的内容看起来像是带有回调函数的JSON响应。
不知道你是如何处理响应我假设“cbfunc”函数被调用。
function cbfunc(response){
var oResponse = jQuery.parseJSON(response);
//Get the 1st quote in the array
var quote1 = oResponse.query.results.quote[0];
}