I am working with jquery ajax & the ajax response is multidimensional json array, I am assinging the JSON values to coordinates array & then assinging coordinates array to new JSON coord_set, after assinging all values to coord_set, It takes last array values to all,
for e.g. the JSON result contains following values
obj[0]={125, 343, 456, 453},
obj[1]={345, 657, 234, 787},
obj[2]={980, 677, 657, 568}
after assinging to new JSON the values are:
coord_set[0] = {
fillColor : 'rgba(255, 234, 111 ,0.5)',
data : [980, 677, 657, 568]
}
coord_set[1] = {
fillColor : 'rgba(255, 234, 111 ,0.5)',
data : [980, 677, 657, 568]
}
coord_set[2] = {
fillColor : 'rgba(255, 234, 111 ,0.5)',
data : [980, 677, 657, 568]
}
This is my code:
var obj = JSON.parse(data);
for(var j=0;j<obj.length;j++)
{
for (var i=0;i<obj[j].length;i++)
{
coordinates[i] = obj[j][i].how_many;
}
coord_set[j] = { fillColor : 'rgba(255, 234, 111 ,0.5)', data : coordinates };
}
alert(JSON.stringify(coord_set));
Please tell me, If I am doing Anything wrong in my code?