简体   繁体   English

将对象(json).json巨人保存在javascript文件中

[英]save an object (json) .json giant in a file in javascript

I'm doing a Three.js development. 我正在做Three.js开发。 specifically I am creating meses in THREE.JS but as charge thousands of vertices, takes a long time in the figures created. 具体来说,我正在THREE.JS中创建混乱,但由于要填充成千上万个顶点,因此创建的图形需要花费很长时间。 So my idea is to save the object that is created in .json format so that when you run the application simply need to load the .json and so do not delay. 因此,我的想法是保存以.json格式创建的对象,以便在运行应用程序时只需要加载.json即可,因此不要延迟。

I tried using the library: DEBUGOUT 我尝试使用该库: DEBUGOUT

but the json is so great that the browser crashes (I think). 但是json太好了,以至于浏览器崩溃了(我认为)。 I have also tried to: 我也尝试过:

JSON.stringify ()

to make a copy and paste, but I get an error as cyclic structure something. 进行复制和粘贴,但由于循环结构而出现错误。 from google chrome I tried to save as a temporary variable but do: 从谷歌浏览器我试图另存为临时变量,但这样做:

copy (temp1);

I get [object Object] What I can do? 我得到[object Object]我能做什么?

this is my json: 这是我的json:

http://i.imgur.com/Db4feaP.png http://i.imgur.com/Db4feaP.png

I need sabe my .json in a file.. thank you! 我需要一个文件中的sabe我的.json。谢谢!

I think you will be very happy if you try out Firebase, which will store and retrieve your json object trivially. 我认为,如果您尝试Firebase,它将很高兴,它将轻松地存储和检索json对象。

Here is an example where they store the pixels of a canvas object in firebase : https://www.firebase.com/tutorial/#session/x0mesao7io1 这是一个示例,他们在firebase中存储画布对象的像素: https : //www.firebase.com/tutorial/#session/x0mesao7io1

code looks basically like this: 代码基本上是这样的:

var ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog");

var usersRef = ref.child("users");
usersRef.set({
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  },
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"
  }
});

Also you'll be happy to know that Firebase will work even if you're offline, then it will sync when online. 另外,您也很高兴知道即使您处于离线状态,Firebase仍能正常工作,然后它在联机时也会同步。

UPDATED: If the object you are trying to save cannot be converted to json, then what you need to do is separate the main data from the object, and store that. 更新:如果您要保存的对象无法转换为json,那么您需要做的就是将主要数据与对象分离,然后进行存储。 So to reload your data, you will recreate the basic structure of the object in javascript, then insert the data into the object. 因此,要重新加载数据,您将在javascript中重新创建对象的基本结构,然后将数据插入到对象中。

It's hard to tell where the vertices are stored in your object from the image, but it seems like what you may want to do is actually extract just the vertices data and save that, or something similar. 很难说出顶点在图像中存储在对象中的位置,但是似乎您可能想要做的实际上只是提取顶点数据并将其保存,或类似方法。

UPDATE2: It seems threejs may have a .toJSON() function that you need to use to extract it as a json object: https://github.com/josdirksen/learning-threejs/blob/master/chapter-08/03-load-save-json-object.html this example shows converting the threejs object to a json, and storing, loading the json, then recreating the threejs object. UPDATE2:似乎threejs可能具有一个.toJSON()函数,您需要使用该函数将其提取为json对象: https : //github.com/josdirksen/learning-threejs/blob/master/chapter-08/03- load-save-json-object.html此示例显示了将threejs对象转换为json,然后存储,加载json,然后重新创建threejs对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM