1

Can anyone guide me how I do this in Javascript? Create an object with two methods. It should stringify and parse JSON, ie it has a method of serializing an object structure, and another method for deserializing, converting a JSON string into an object structure.

Methods Should handle circular references, not kracha or retunera an empty result.

Xtreme
  • 1,601
  • 7
  • 27
  • 59
  • possible duplicate of [how to parse json in javascript](http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript) and [serializing object that contains cyclic object value](http://stackoverflow.com/questions/9382167/serializing-object-that-contains-cyclic-object-value) -- please use the search before you ask a new question. – Felix Kling May 07 '12 at 10:53
  • *Methods Should handle circular references* How exactly should they be handled? – Felix Kling May 07 '12 at 10:55

2 Answers2

4

Use JSON.parse

var originalObject = { foo: "bar" };
var jsonString = JSON.stringify( originalObject ); // "{foo:'bar'}"
var objectFromString = JSON.parse( jsonString );   // { foo: "bar" }
noob
  • 8,982
  • 4
  • 37
  • 65
0

Err.. JSON.parse and JSON.stringify? It's pretty much supported these days.

Joseph
  • 117,725
  • 30
  • 181
  • 234