##########1.json字符串转json数组###########
var str="[{name:'zhangsan',age:'24'},{name:'lisi',age:'30'},{name:'wangwu',age:'16'},{name:'tianqi',age:'7'}] ";
var myobj=eval(str);
//var myobj= eval('(' + str + ')');
for(var i=0;i<myobj.length;i++){
alert(myobj[i].name);
alert(myobj[i].age);
}
##########2.json字符串转json对象###########
JSON字符串:
var str1 = '{ "name": "cxh", "sex": "man" }';
JSON对象:
var str2 = { "name": "cxh", "sex": "man" };
//由JSON字符串转换为JSON对象
var obj = eval('(' + str1 + ')');
然后,就可以这样读取:
Alert(obj.name);
Alert(obj.sex);