點選頁面右下角“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>