标签:
eval() 将字符串作为js语句解析
//jsonString是一个JSON格式的字符串 var data = eval(‘(‘ + jsonString + ‘)‘); console.dir(data); document.write(eval("1+1"));
stringify() 将JSON对象转换为JavaScript对象表示法的JSON字符串(对象转为字符串)
var jsonString = JSON.stringify(object); var people = new Object(); people.name = "Larry"; people.sex = "famle"; people.address = "Shanghai"; var jsonPeople = JSON.stringify(people); alert(typeof jsonPeople); //string alert(jsonPeople);
parse() 将JavaScript对象表示法的JSON字符串转换为对象(字符串转对象)
var jsonObj= JSON.parse(jsonStr); var jsonStr = ‘{"name":"Larry","sex":"famle","address":"Shanghai"}‘ var jsonObj= JSON.parse(jsonStr);
alert(typeof jsonObj); //Object alert(jsonObj);
标签:
原文地址:http://www.cnblogs.com/zcynine/p/4987281.html