supermedium / beatsaver-viewer

⚔️ Web-based viewer for Beat Saver maps, built with A-Frame and JavaScript.
https://supermedium.com/beatsaver-viewer/?id=811-535&difficulty=Expert
MIT License
192 stars 32 forks source link

"Unexpected token" for JSON files with non-UTF-8 encoding #14

Closed n3tman closed 5 years ago

n3tman commented 5 years ago

Some songs can't be previewed and display an error:

Uncaught SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at ZipLoader.extractAsJSON (build.js:274)
    at Object.keys.forEach.filename (build.js:96)
    at Array.forEach (<anonymous>)
    at ZipLoader.loader.on (build.js:96)
    at ZipLoader.dispatch (build.js:274)
    at XMLHttpRequest.xhr.onload (build.js:274)

This is due to non-UTF-8 encoding in .json files (checked with Notepad++).

Examples of UCS-2 LE BOM in info.json:

  1. https://supermedium.com/beatsaver-viewer/?id=5239-4638
  2. https://supermedium.com/beatsaver-viewer/?id=10606-11164
  3. https://supermedium.com/beatsaver-viewer/?id=10880-11495
ngokevin commented 5 years ago

Thanks, I had some code to normalize it, I’ll add it later.

ngokevin commented 5 years ago

Should run now. Though the text might be malformatted, at least plays.

n3tman commented 5 years ago

Sorry to bother, but still reproduced here: https://supermedium.com/beatsaver-viewer/?id=11637-12380 Our Korean friends do like strange encodings.. I guess it's default on their PCs. Even though all the mapping guides clearly state - use UTF-8 only. So you might ignore this 😅

ngokevin commented 5 years ago

We can't live without kpop!

ngokevin commented 5 years ago

https://github.com/supermedium/beatsaver-viewer/commit/d8ee31b16e9b95c378abe1d14cc49e2d8a02f6c3