I thought I was doing this correct but this might be a total noob mistake.
Here is my JSON data
{
"rows": {
"row1": {
"divs": 7,
"offset": 0,
"colors": {
"color1": "#003366",
"color2": "#336699",
"color3": "#3366CC",
"color4": "#003399",
"color5": "#000099",
"color6": "#0000CC",
"color7": "#000066"
}
},
"row2": {
"divs": 8,
"offset": 11,
"colors": {
"color1": "#006666",
"color2": "#006699",
"color3": "#0099CC",
"color4": "#0066CC",
"color5": "#0033CC",
"color6": "#0000FF",
"color7": "#3333FF",
"color8": "#333399"
}
},
"row3": {
"divs": 9,
"offset": 22,
"colors": {
"color1": "#669999",
"color2": "#009999",
"color3": "#33CCCC",
"color4": "#00CCFF",
"color5": "#0099FF",
"color6": "#0066FF",
"color7": "#3366FF",
"color8": "#3333CC",
"color9": "#666699"
}
}
}
}
I saved it to a file and pushed it into an array like this
var colorPicker = []
$(function () {
$.getJSON("js/json/colorPicker.json", function (data) {
colorPicker.push(data)
});
})
Now I am trying to access this array.
I can get into it doing colorPicker[0]
That will return the whole object.
Object {rows: Object}
When I do colorPicker[0].rows
it will return the 3 rows
Object {row1: Object, row2: Object, row3: Object}
But when I do colorPicker[0][1]
shouldn't that give me just one the rows?
I keep on getting undefined.
When I do colorPicker[0].rows.row1
Then I can access my values from there. But if I want to use a for each loop it would be easier to do something like colorPicker[0][1].divs
, wouldent it? Am I approaching this wrong?