JAVASCRIPT:js生成json数组

代码:

var datas = [];

var data  = {};  
data["id"]       = 1;  
data["name"]     = "test" + 1;  
data["age"]      = 1 * 2;  
datas.push(data);  

var jsonString   = JSON.stringify(datas);  //[{"id":1,"name":"test1","age":2}]  
msg.innerHTML    = jsonString;  
var epc          = eval("("+jsonString+")");  

alert(epc[0].id);

 

本文:JAVASCRIPT:js生成json数组

Leave a Reply