How To Load Json Data In Cocos2d-x 3.0 In Javascript
How would one load a javascript structure (object or array) from a file in Cocos2d-X 3. My res/test.json: { version:'1.0', data:'this is some data.' } I'm able to load the
Solution 1:
The "standard" JSON.parse
works:
var fileUtil = cc.FileUtils.getInstance();
vardata = fileUtil.getStringFromFile('res/test.json');
var jData = JSON.parse(data);
But note all attribute names must be passed in quotes, otherwise the parser will fail. res/test.json
must then look like this:
{"version":"1.0","data":"this is some data."}
Post a Comment for "How To Load Json Data In Cocos2d-x 3.0 In Javascript"