Jump to content

format json problem


espace
 Share

Recommended Posts

hi,

I use this function to to set the storage  :

var logic_position=function(sprite){
	if (debug_position){
		hero.grid.visible=false	;
		var _table;
		var _name_json;
		switch(sprite.name){
			case 'canon':
				_table=c;
				_name_json='canon';
				_table[sprite.number] = {
					number:sprite.number,
					delay:Math.round(sprite.delay),
					x:Math.round(sprite.x),
					y:Math.round(sprite.y),
					speed:Math.round(sprite.speed),
					frequency:Math.round(sprite.frequency),
					variance:Math.round(sprite.variance),
					angular:Math.round(sprite.angular),
					_flag:sprite._flag,
					kill_with_world:sprite.kill_with_world,
					special_color:sprite.special_color,
					_rotate:sprite._rotate,
					_value_rotate:sprite._value_rotate,
				};
				break;			
		}
		this.level=level_number;
		this.name_level='lev';
		this.combined_level=this.name_level+this.level;
		localStorage.setItem(_name_json+sprite.number+this.combined_level, JSON.stringify(_table[sprite.number]),null,"\t");
	}
};

console.log(localStorage)

The result of the localStorage is this :

{
	"canon0lev0": "{\"number\":0,\"delay\":0,\"x\":200,\"y\":840,\"speed\":2000,\"frequency\":60,\"variance\":20,\"angular\":180,\"_flag\":false,\"kill_with_world\":true,\"special_color\":false,\"_rotate\":false,\"_value_rotate\":10}"
}

And what i want is this :

{
canon0lev0:{ 
number:0,
delay:0,
x:200,
y:840,
speed:2000,
frequency:60,
variance:20,
angular:180,
_flag:false,
kill_with_world:true,
special_color:false,
_rotate:false,
_value_rotate:10}
}
}

However i follow this link to format my json but it's not the result expected

https://stackoverflow.com/questions/2614862/how-can-i-beautify-json-programmatically

What i must do to have the result expected...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...