简体   繁体   中英

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

I'm doing a Three.js development. specifically I am creating meses in THREE.JS but as charge thousands of vertices, takes a long time in the figures created. 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.

I tried using the library: DEBUGOUT

but the json is so great that the browser crashes (I think). 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?

this is my json:

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

I need sabe my .json in a file.. thank you!

I think you will be very happy if you try out Firebase, which will store and retrieve your json object trivially.

Here is an example where they store the pixels of a canvas object in 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.

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. So to reload your data, you will recreate the basic structure of the object in javascript, then insert the data into the object.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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