Weebly Uncaught SyntaxError:意外的令牌<在位置0的JSON中

时间:2018-05-06 17:51:00

标签: json unity3d syntax-error weebly unexpected-token

我正在尝试为我的Weebly网站实施我的Unity应用程序。我遵循了本教程: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 :(得分:0)

您使用的网址有空格。正确的网址没有。

改变这个:

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");

答案 1 :(得分: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