J
var jsonObject = {
"name":"123",
"age":12,
"address":{"city":"beijing","school":"一中"},
"teaching":function(){
alert("JAVAEE");
}
};
alert(jsonObject.name); //123
jsonObject.teaching(); //JAVAEE
如何把字符串转换成JSON对象
使用eval()方法:它会转为本地的JS代码来执行
//把一个字符串转换为JSON对象
//使用eval()方法
var testStr = "alert('hello eval')"
eval(testStr); //hello eval
var jsonStr = "{'name':'123'}";
var testObject = eval("("+jsonStr+")");
alert(testObject.name); //123