CodePanda CodePanda - 4 months ago 10
jQuery Question

Trying to store json data into an javascript array

I have the following json data that looks like this...

enter image description here

What I am trying to do is store the temp numbers into a javascript array to display on a graph. This is my code that I was working on...



$.ajax({
type: 'GET',
url: "http://api.openweathermap.org/data/2.5/forecast?q=Redlands,us&mode=json&units=imperial&cnt=20&APPID=5eea63b2ee3505c58713d9149832d4c5",
dataType: 'json',
success: function(data){
//console.log(data.list[0].main.temp);
//trying to parse through data for graph
var date = [];
$.each(data,function(index, data){
date.append(data.list[index].main.temp);
});

}


});





But it is not working I get the following error...
Uncaught TypeError: Cannot read property 'city' of undefined

Anyone know how I can fix this?

Answer

i see working , same from Erik Engervall, i change var data for current

    $.each(data.list,function(index, current){
                date.push(current.main.temp);
     });
Comments