[ 5 posts ]

Stuart Grimshaw

  • Username: Stubbs
  • Joined: Sun Jun 10, 2012 6:36 am
  • Posts: 11
  • GitHub: Stubbs
  • Gists: Stubbs
  • IRC: Stubbs
  • Offline
  • Profile

Serialize a "Graphic" object's shapes to JSON

Post Posted: Sat Jun 30, 2012 3:27 pm
+0-
When I try and serialize the shapes on a Graphic object, it throws Converting circular structure to JSON

My code looks like this:

Code:
    var shapes = FC.pitch.get('shapes');
    Y.one('#objects').set('text', Y.JSON.stringify(shapes, shapes));


How do you serialise the shapes on my Graphic?

Alberto Santini

YUI Contributor

  • Offline
  • Profile
Tags:

Re: Serialize a "Graphic" object's shapes to JSON

Post Posted: Sun Jul 01, 2012 12:08 am
+0-
Hello Stuart.

The following snippet reproduce the case with a simple circular object:
http://jsfiddle.net/WkdE6/

The behaviour is correct and it depends on your graphic object.

However it seems there is a Douglas's implementation to workaround that:
https://github.com/douglascrockford/JSON-js

This is a review about cycle.js:
http://realgl.blogspot.it/2012/05/cyclic-json.html

And a working jsfiddle using that idea:
http://jsfiddle.net/snaGx/

Hope that helps,
IceBox

P.S.: If the serialization is required for debugging purpose, it may feasible to use the debugger tools.

Stuart Grimshaw

  • Username: Stubbs
  • Joined: Sun Jun 10, 2012 6:36 am
  • Posts: 11
  • GitHub: Stubbs
  • Gists: Stubbs
  • IRC: Stubbs
  • Offline
  • Profile
Tags:

Re: Serialize a "Graphic" object's shapes to JSON

Post Posted: Mon Jul 23, 2012 10:05 am
+0-
Hi Alberto,

I'm trying to serialize the shapes on my Graphic object so I can save them to a remote server.

I take it the techniques you describe aren't built in to YUI be default?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Serialize a "Graphic" object's shapes to JSON

Post Posted: Mon Jul 23, 2012 10:18 am
+0-
Hello Stuart.

Converting circular structure to JSON is not an issue related with YUI, but with JSON.

Regards,
IceBox

Stuart Grimshaw

  • Username: Stubbs
  • Joined: Sun Jun 10, 2012 6:36 am
  • Posts: 11
  • GitHub: Stubbs
  • Gists: Stubbs
  • IRC: Stubbs
  • Offline
  • Profile

Re: Serialize a "Graphic" object's shapes to JSON

Post Posted: Mon Jul 23, 2012 11:17 pm
+0-
I understand that normally it wouldn't be a YUI issue, but with the structure I'm serialising being an internal one to the YUI library, I thought it might be a common enough use case for engineers that it had been tackled already.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum