首页 > 代码库 > JSON

JSON

1.字符串转换成json对象

var txt = {"employees":[ +{"firstName":"Bill","lastName":"Gates" }, +{"firstName":"George","lastName":"Bush" }, +{"firstName":"Thomas","lastName":"Carter" }]};方法①.var obj = eval ("(" + txt + ")");方法②.var obj = JSON.parse(txt);---更安全
访问:document.getElementById("fname").innerHTML=obj.employees[1].firstName

 

JSON