Ajax当中json的用法
3.json
例 3.1(eval1.html)
<HTML>
<HEAD>
<TITLE>在eclipse中直接open with火狐即可</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
//例1
var s = "2+41-19";
alert(eval(s));
eval("d =new Date();alert(d.toLocaleString())")
//-->
</SCRIPT>
</BODY>
</HTML>
例 3.2(eval2.html)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var user ="{name:'某',sex:'男',age:22}";
var obj = eval("("+user+")"); //多加一对()为语法要求
alert(obj.age);
for(var pro in obj)
{
alert(obj[pro]);
}
//-->
</SCRIPT>
</BODY>
</HTML>
例 3.3(eval3.html)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
define = "{name:'Michael',email:'17bity@gmail.com'}";
eval("data = "+define);
alert(data.name);
alert(data.email);
//-->
</SCRIPT>
</BODY>
</HTML>
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/103051356