0

I am new to JQuery and JSON. I am having trouble returning a value from

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);
        }
) 
});
});

example 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]]}]}

rest ommited for brevity.

How can I retrieve the first value in the data array: "20151012",2.556 <-- need this...

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101

1 Answers1

0

You are missing a period:

var content = data.series[0].data[0][1]

Malk
  • 11,855
  • 4
  • 33
  • 32