javascript脚本中使用json2.js解析json
点击页面右下角“Download ZIP”下载
网页中引用json2.js,下面是一个简单的例子,直接上例子,很容易看的懂,不再做解释:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>json2.js的使用</title> </head> <body> <div id="msg"></div> <div id="msg2"></div> <script src="json2_min.js" type="text/javascript"></script> <script type="text/javascript"> var user={ UserName: "张三", Sex: "男" }; var str=JSON.stringify(user); document.getElementById("msg").innerHTML="序列化:"+str; var obj=JSON.parse(str); document.getElementById("msg2").innerHTML="反序列化:"+"姓名:"+obj.UserName; document.getElementById("msg2").innerHTML+=" 性别:"+obj.Sex; </script> </body> </html>