Accessing multiple JSON files in JavaScript -
i have sprite sheets atlus saved in json format. i'm structuring atlus based upon structure browserquest. each of json files looks like:
{ "id": "agent", "width": 24, "height": 24, "animations": { "idle_down": { "length": 2, "row": 0 } }, "offset_x": -4, "offset_y": -8 }
but i'm wondering, how access data in each json file, if raw object literal?
since each json file object literal, way imagine accessing save object literal variable, such as
var agent = { "id": "agent", "width": 24, "height": 24, "animations": { "idle_down": { "length": 2, "row": 0 } }, "offset_x": -4, "offset_y": -8 };
i'm hoping there easy way access json files.
and because each individual sprite sheet has own json file, have large number of files load.
what best way load such high number of json files? i'm trying avoid using js libraries.
first, answer questions:
but i'm wondering, how access data in each json file, if raw object literal?
json stands javascript object notation, , such identical how manipulated if javascript object.
as accessing json file if local file, use this:
function dostuff(json){ console.log(json); } var oreq = new xmlhttprequest(); oreq.addeventlistener("load", function(){ dostuff(json.parse(this.responsetext)); }); oreq.open("get", "http://www.example.com/example.json"); oreq.send();
and can replace dostuff
whatever function handles json.
Comments
Post a Comment