如下的html文件,user.html.需要到
https://github.com/douglascrockford/JSON-js/blob/master/json.js 下载json.js
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <title> New Document </title>
5 <meta name="Generator" content="EditPlus">
6 <meta name="Author" content="">
7 <meta name="Keywords" content="">
8 <meta name="Description" content="">
9 </head>
10
11 <body>
12 <script>
13 var my_json='{"FBI":{"length":2,"context":[{"name":"rose","age":25},{"name":"qinlei","age":30}]}}'
14 var my_object=eval('('+my_json+')');
15 document.writeln(my_object.FBI.length);
16 for(i=0;i<my_object.FBI.length;++i)
17 {
18
19 document.writeln(my_object.FBI.context[i].name);
20 document.writeln(my_object.FBI.context[i].age);
21
22 }
23
24 </script>
25 <script src="json.js"></script>
26 <script>
27 var my_object={
28 FBI:[
29 {name:"rose",age:"25"},
30 {name:"jack",age:"25"}
31 ],
32 NBA:[
33 {name:"tom",sex:"man"},
34 {name:"jack",sex:"women"}
35 ]
36 };
37 document.writeln(my_object.toJSONString());
38 </script>
39 </body>
40 </html>
41