JSON进阶(一)
2010-09-14 13:44:19 来源:WEB开发网二、 Json对象--字符串
1 <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4 <head>
5 <title>My JSP '1.jsp' starting page</title>
6 <script type="text/javascript" src="js/json.js"></script>
7 </head>
8 <body>
9 <script type="text/javascript">
10 function test()
11 {
12 var myJSONtext =
13 {
14 "bindings":
15 [
16 {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
17 {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
18 {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
19 ]
20 };
21 var myObject = eval(myJSONtext);
22 alert("对象长度:"+myObject.bindings.length);
23 for(var i=0;i<myObject.bindings.length;i++){
24 alert(myObject.bindings[i].method);
25 }
26 }
27 </script>
28 <input type="button" onclick="test()" value="使用这个script" />
29 </body>
30 </html>
31
更多精彩
赞助商链接