0

我正在尝试为我的 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.

我怎样才能解决这个问题?

4

2 回答 2

0

您使用的 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");
于 2018-05-06T18:10:05.480 回答
0

您需要设置一个 Web 服务器。

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

于 2019-07-09T08:17:50.367 回答