Riddik Posted July 6, 2014 Share Posted July 6, 2014 Hi! In FireFox browser loader freezes at the moment loading my .json file with error message in console:SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data phaser-arcade-physics.min.js:13My .json file: [{"bg":"day","spawn":[ {"monster_type":"0","time":"1"}, {"monster_type":"0","time":"4"}, {"monster_type":"1","time":"3"}, {"monster_type":"0","time":"3"}, {"monster_type":"1","time":"2"}, {"monster_type":"2","time":"3"}, {"monster_type":"2","time":"4"}, {"monster_type":"1","time":"1"}]},{"bg":"day","spawn":[ {"monster_type":"1","time":"1"}, {"monster_type":"0","time":"4"}, {"monster_type":"2","time":"3"}, {"monster_type":"1","time":"3"}, {"monster_type":"0","time":"2"}, {"monster_type":"2","time":"3"}, {"monster_type":"1","time":"4"}, {"monster_type":"1","time":"1"}]}]What is my mistake? Link to comment Share on other sites More sharing options...
wayfinder Posted July 6, 2014 Share Posted July 6, 2014 Try removing the outermost "[" and "]" Link to comment Share on other sites More sharing options...
Riddik Posted July 6, 2014 Author Share Posted July 6, 2014 Tried. In FireFox message is unchanged, and in Chrome: Uncaught SyntaxError: Unexpected token , Link to comment Share on other sites More sharing options...
lewster32 Posted July 6, 2014 Share Posted July 6, 2014 This is valid JSON so I don't see why it's not parsing. Possibly an encoding issue? Can you make sure the file is being saved and served as UTF-8? clark and Riddik 2 Link to comment Share on other sites More sharing options...
clark Posted July 6, 2014 Share Posted July 6, 2014 I am having this issue with only IPod 4 (That I have tested) my en.json language file just refuses to load on that device. It has passed json validation. I will check the encoding, thanks lewster again Link to comment Share on other sites More sharing options...
ragnarok Posted July 6, 2014 Share Posted July 6, 2014 I think JSON needs to be encapsulated by an actual object, so instead of this array...[{"bg":"day","spawn":[...]},{"bg":"day","spawn":[...]}]...try this..{ "data":[ {"bg":"day","spawn":[...]}, {"bg":"day","spawn":[...]} ]} Riddik 1 Link to comment Share on other sites More sharing options...
Riddik Posted July 6, 2014 Author Share Posted July 6, 2014 Oh, file was with utf-8 encoding, i changed to ANSI and file loaded successfully! Very strange. Vice versa ). Thank you for hint about encoding! Link to comment Share on other sites More sharing options...
lewster32 Posted July 6, 2014 Share Posted July 6, 2014 I know very little about how encoding affects the parsing of files - I suspect the HTML or JavaScript (or both) have to match the encoding of the file you're trying to load in some browsers, but I can't confirm this. The JSON spec makes it plain that UTF-8 should be used - to quote the spec: 3. EncodingJSON text SHALL be encoded in Unicode. The default encoding is UTF-8. Also, your error seems to indicate that the problem may be in the very first character, which in Unicode files is where the BOM (byte order mark) is placed. It's certainly caused a few seemingly bizarre issues before for me which is why I suggested it. Can anyone shed any light on this and clear it up? I realise it's not a Phaser related issue per se, but still... Link to comment Share on other sites More sharing options...
Riddik Posted July 6, 2014 Author Share Posted July 6, 2014 All JavaScript files were utf-8, except "phaser-arcade-physics.min.js" file - it is in ANSI. For test I changed this file encoding to UTF-8 and changed back my .JSON file to UTF-8. And again firefox can't load my json. Link to comment Share on other sites More sharing options...
rich Posted July 7, 2014 Share Posted July 7, 2014 UTF-8 is the correct encoding format to use. What Firefox can't load is UTF-16 (and a variety of other formats), which is the default format generated by tools like Adobe Flash CC when exporting sprite sheets. Also be aware of how your web server is handling the files and check it's not re-encoding them (some do!) Link to comment Share on other sites More sharing options...
Recommended Posts