我是JQuery和JSON的新手。我无法从
返回值jQuery(document).ready(function($) {
$.getJSON(
'http://api.eia.gov/series/?api_key=YourAPIKey&series_id=PET.EMD_EPD2D_PTE_NUS_DPG.W',
function(data){
var content = data series[0].data[0][1]
$('p').append(content);
}
)
});
});
示例json:
{"request":{"command":"series","series_id":"PET.EMD_EPD2D_PTE_NUS_DPG.W"},"series":[{"series_id":"PET.EMD_EPD2D_PTE_NUS_DPG.W","name":"U.S. No 2 Diesel Retail Prices, Weekly","units":"Dollars per Gallon","f":"W","unitsshort":"$\/gal","description":"U.S. No 2 Diesel Retail Prices","copyright":"None","source":"EIA, U.S. Energy Information Administration","iso3166":"USA","geography":"USA","start":"19940321","end":"20151012","updated":"2015-10-14T09:50:13-0400","data":[["20151012",2.556],["20151005",2.492],["20150928",2.476],["20150921",2.493],["20150914",2.517],["20150907",2.534],["20150831",2.514],["20150824",2.561],["20150817",2.615],["20150810",2.617],["20150803",2.668],["20150727",2.723],["20150720",2.782],["20150713",2.814],["20150706",2.832],["20150629",2.843],["20150622",2.859], ["20150615",2.87],["20150608",2.884],["20150601",2.909]]}]}
为了简洁而无所不知。
如何检索数据数组中的第一个值:“20151012”,2.556< - 需要这个......
答案 0 :(得分:0)
你错过了一段时间:
var content = data.series[0].data[0][1]