//带变量的字符串
var str = 'var a=1; var b=2;'; eval(str); alert(a+b);//结果 3;
//数组字符串
var arrStr = "[1,2,3,4]";
eval(arrStr);
arrStr = [1,2,3,4];//转化结果
//json对象字符串
var jsonStr = "{name:'xiao',sex:'man'}";
eval(jsonStr);
arrStr ={name:'xiao',sex:'man'};//转化结果
//json 对象转化为json 字符串
var
student =
new
Object();
student.name =
"Lanny"
;
student.age =
"25"
;
student.location =
"China"
;
var
json = JSON.stringify(student);
alert(student);