Weebly Uncaught SyntaxError: Неожиданный токен <в JSON в позиции 0 - PullRequest
0 голосов
/ 06 мая 2018

Я пытаюсь внедрить мое приложение Unity для моего сайта Weebly. Я следовал этому уроку: https://www.youtube.com/watch?v=mf-yNlMLcqA

У меня есть два кода:

1

 <!DOCTYPE html>
 <html lang="en-us">
 <head>
 <meta charset="utf-8">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <title>Unity WebGL Player | LearningEffective</title>
 <script 
 src="https://pamaentertainment.weebly.com/files/theme/Build/UnityLoader.js"> 
 </script>
 <script>
 var gameInstance = UnityLoader.instantiate("gameContainer", 
 "https://pamaentertainment.weebly.com/files/theme/Build/Learning Effective 
 online.json");
 </script>
 </head>
 <body>
 <div id="gameContainer" style="width: 720px; height: 1280px; margin: auto"> 
 </div>
 </body>
 </html>

2

{
"companyName": "pama",
"productName": "LearningEffective",
"dataUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.data.unityweb",
"asmCodeUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.code.unityweb",
"asmMemoryUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.memory.unityweb",
"asmFrameworkUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.asm.framework.unityweb",
"TOTAL_MEMORY": 268435456,
"graphicsAPI": ["WebGL 2.0", "WebGL 1.0"],
"webglContextAttributes": {"preserveDrawingBuffer": false},
"backgroundUrl": "https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.jpg",
"splashScreenStyle": "Dark",
"backgroundColor": "#FFFFFF"
}

Когда я пытаюсь загрузить страницу, на которой находится код для встраивания Weebly, Chrome открывает следующее окно: Uncaught SyntaxError: Unexpected token < in JSON at position 0.

Как я могу это исправить?

Ответы [ 2 ]

0 голосов
/ 09 июля 2019

Вам необходимо настроить веб-сервер.

IIS - в файле web.config:

<mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
<mimeMap fileExtension=".unityweb" mimeType="application/octet-stream" />

Apache - в файле .htaccess:

AddType application/octet-stream unityweb
AddType application/json json

https://forum.unity.com/threads/webgl-uncaught-syntaxerror-unexpected-token-in-json-at-position-0.466784/

https://answers.unity.com/questions/1397472/webgl-build-when-uploaded-gives-me-this-error-unca.html

0 голосов
/ 06 мая 2018

URL, который вы используете, содержит пробел. У правильного URL его нет.

Изменить это:

var gameInstance = UnityLoader.instantiate("gameContainer", 
"https://pamaentertainment.weebly.com/files/theme/Build/Learning Effectiveonline.json");

К этому:

var gameInstance = UnityLoader.instantiate("gameContainer", 
"https://pamaentertainment.weebly.com/files/theme/Build/LearningEffectiveonline.json");
...