简体   繁体   中英

How to convert javascript associative array to json and use later using parseJSON?

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"])

JSON.stringify()

JSON.parse()

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