javascript - How to convert large JSON string into array with JQuery -


this question has answer here:

i have json string looks this:

[     {         "id": "acbpreviewcell",         "width": 80     },     {         "id": "advname",         "width": 170     },     {         "id": "adheadline",         "width": 150     },     {         "id": "adsize",         "width": 150     },     {         "id": "adproduct",         "width": 150     },     {         "id": "adcategory",         "width": 150     },     {         "id": "adsection",         "width": 150     },     {         "id": "adcolor",         "width": 150     },     {         "id": "adtags",         "width": 150     },     {         "id": "adregions",         "width": 150     },     {         "id": "adstatus",         "width": 150     },     {         "id": "adcreated",         "width": 150     },     {         "id": "adbookingnb",         "width": 150     },     {         "id": "adpickup",         "width": 150     },     {         "id": "foliometa",         "width": 150     } ] 

to explain further, each of these entries id of table header, along width of table header. i'm using within application can remember user's custom column width set.

i break json string down javascript array, can access each id , it's width.

any appreciated setting array , breaking down access id , width. thank you!

if want convert array can use built-in json object parse it: json.parse(yourstring).

but if want access values id, have convert object:

var originaldata = json.parse(yourstring); var parseddata = {}; (var = 0, l = originaldata.length; < l; i++) {     parseddata[originaldata[i].id] = originaldata[i].width; }  // can access wanted widths var acbpreviewcellwidth = parseddata['acbpreviewcellwidth']; 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -