我正在寫一個Three.js應用程序。在其中的一部分中,我使用Blender->JSON exporter爲Three.js加載了作爲JSON文件導出的攪拌機模型。我在我的本地計算機(Windows 7)上配置了WAMPServer 2.2,用於在將它FTP到遠程服務器以向朋友等炫耀之前測試我的網站。Javascript:Three.js遠程服務器上的JSON錯誤,但不是本地的
加載該JSON文件工作正常,本地測試服務器上,但是當我把它上傳到服務器上,我得到了螢火蟲,火狐16.0.2以下錯誤:
SyntaxError: JSON.parse: unexpected character
var json = JSON.parse(xhr.responseText);
three.js (line 7810)
它找到JSON文件很好 - GET顯示在Firebug中。就我所知,模型的加載是我在整個腳本中唯一加載的JSON;該模型也不會在本地進行遠程顯示。下面是在它負載的功能:
//Adds a unit to the scene. Assumes Init() hasn't been called on the unit yet.
function pubAddUnit(unit, coord, modelSrc)
{
//Do whatever initialization the unit has to do
unit.Init();
//Store the unit in its position on the grid
units[coord.y][coord.x] = unit;
//Load the unit model
var loader = new THREE.JSONLoader();
loader.load(modelSrc,
//Function called once the unit model is loaded
function(geometry) {
//Create a new material for the unit
var material = new THREE.MeshFaceMaterial();
var mesh = new THREE.Mesh(geometry, material);
//Store the unit geometry and mesh into their respective grids
unit.SetGeo(geometry);
unit.SetMesh(mesh);
//Move the mesh to the correct spot
mesh.position = TransCoord2(coord);
mesh.scale.set(40, 40, 40);
//Add the mesh to the scene
scene.add(mesh);
//Update the scene, now with the mesh in
update();
});
}
而且here's the javascript file,作爲顯示在遠程服務器上。關於爲什麼會發生這種情況的任何想法,
編輯:我使用FileZilla到FTP。我突然注意到服務器上的JSON文件的文件大小與本地文件大小不同,但我不確定這是否是我需要擔心的事情 - 也許它是行結尾或什麼?
使用數字json驗證器之一,如http://jsonlint.com/ – zerkms
@zerkms我已經做到了,它通過驗證罰款(本地版本和我從服務器下載的遠程版本,再次使用FileZilla中)。 – Chaosed0
所以解析器說它壞了,我們目前沒有看到它。你期待什麼樣的幫助? – zerkms