function jsonDecode(data){
return new Function("return "+data+";")();
}
var a = (jsonDecode("[{id:1},{id:2}]"));
alert(a[0].id);
我们现在的安全检查是不允许使用eval,认为有安全隐患,至于会产生什么隐患没有做深入了解。
所以使用上述方法去讲字符串解析为array数组。
function jsonDecode(data){
return new Function("return "+data+";")();
}
var a = (jsonDecode("[{id:1},{id:2}]"));
alert(a[0].id);