[jQuery] Convert a string version of a json array to an actual json array

2010-01-05 Thread Dave
Hi

Wonder how I can convert a string to a json array.

//start code

var arrCss = [a___{'color':'red','font-weight':'bold'}, h1,h2___
{'color':'blue'}];

for(var i = 0; i  arrCss.length; i++){
   var snip = arrCss[i].split(___);
   $(snip[0]).css(snip[1]);
}

//end code


The problem is that .css() treats snip[1] as a string but I need it to
handle it as a json array.

Bad: .css({'color':'red','font-weight':'bold'});
Good: .css({'color':'red','font-weight':'bold'});

Any solution out there?

Thanks


Re: [jQuery] Convert a string version of a json array to an actual json array

2010-01-05 Thread Md. Ali Ahsan Rana
for(var i = 0; i  arrCss.length; i++){
  var snip = arrCss[i].split(___);
  eval(var temp=+snip[1]);
  $(snip[0]).css(temp);
}


this may work, try it(although i didnt't try yet)


--
http://ranacseruet.blogspot.com