I have some JSON withing an elements attribute and one of the JSON elements has a value of multiple arrays. I have worked out how to access the array if there is one but I’m not sure how to access the second one.
I could also do with knowing how to push a new array to the JSON value.
Here is What I have
$(this).attr({
"data-settings": $.toJSON({ nPosX: newPX, nPosY: newPY, oPosX: oldPX, oPosY: oldPY, moves: ["val"]["key"] })
});
var movesObj = $.parseJSON($(this).attr('data-settings'));
The moves is where the arrays are kept.
Thanks in advanced!
Well, that does not seem like a valid JSON to me. You can’t define a JSON like that. You either define moves like an hash:
you access it like: moves.val or moves[“val”]
Or you define moves like an array of hashes:
You access it like: moves[0].val or moves[0][“val”].
If you want a nested hash like that, you need to define it like:
And access it like moves[“val”][“key”] or moves.val.key