I really hate 'do this for me' questions but I am at a complete loss. I think I just don't get JSON. So here's an example of my JSON:
"max":"10",
"min":"0",
"attributes":[
{
"attributeName":"Fortitude",
"attributeColor":"#B7B7B7"
},
{
"attributeName":"Vigor",
"attributeColor":"#D5A6BD"
},
{
"attributeName":"Celerity",
"attributeColor":"#B4A7D6"
}
]
It's external and I want to grab it, and then set a js variable to act as an array of attribute objects. So if in JS I set:
var attributes = [];
attributes = whatEverNeedsToGoHere;
And then I loop over that variable I could do something like:
console.log(attributes[0].attributeName);
And get "Fortitude". I understand how to get the JSON with jQuery using $.getJSON(); But I don't know get what needs to happen to turn the attributes array into an array of objects.
UPDATE: How I'm calling the JSON in right now.
var attributesData = $.getJSON("jsonDB/attributes.js", function(data){
var thisAttribute = {"attributeName":String(data[i].attributeName),"attributeColor":String(data[i].attributeColor)};
attributes.push(thisAttribute);
console.log(attributes.attributeName);
});