How to convert string to object in js
E.g
[javascript]
var test='{ colkey: "col", colsinfo: "NameList" }'
var test='{ colkey: "col", colsinfo: "NameList" }' is obviously an object, but how to convert text to object. Use eval(); note that parentheses must be added, otherwise the conversion will fail
convert text to object
[javascript]
var test='{ colkey: "col", colsinfo: "NameList" }'
var obj2=eval("("+test+")");
alert(obj2.colsinfo);
var test='{ colkey: "col", colsinfo: "NameList" }'
var obj2=eval("("+test+")");
alert(obj2.colsinfo);
convert text to array
[javascript]
var test='["colkey", "col", "colsinfo","NameList" ]'
var obj2=eval("("+test+")");
alert(obj2.length);