1

Look I want to do this:

function MyObject()
{
  this.attr1;
  this.attr2;
  this.attr3;
}

var myArray = new Array();
myArray["a"] = new MyObject();
myArray["b"] = new MyObject();
myArray["c"] = new MyObject();

var json_myArray = CONVERT_TO_JSON( myArray ); // Or stringify

Finally:

var myOriginalArray = $.parseJSON( json_myArray );

The myOriginalArray and myArray will be identical, including the keys (myOriginalArray["a"])

CRISHK Corporation
  • 2,948
  • 6
  • 37
  • 52
  • 1
    To problems: (a) Arrays should only have numerical indexes, `JSON.stringify` won't consider any other properties. See [JavaScript associative array to JSON](http://stackoverflow.com/questions/4425289/javascript-associative-array-to-json). (b) With this simple object, serialization and deserialization will work as expected, but if you add methods to the functions prototype, things get more complicated. – Felix Kling May 19 '12 at 19:46

1 Answers1

0
JSON.stringify()

and

JSON.parse()
Jivings
  • 22,834
  • 6
  • 60
  • 101