数据加载中……

JSON技术(XML的挑战者)二-----(实战)


下面我们就用JSON来解释服务端返回的数据
1) /data/test_json.js内容
1 {"peoples":[    
2     {"name":"site120",    "email":"site120@163.com",    "sex":""},
3     {"name":"site120_2",    "email":"site120@163.com_2",    "sex":"男_2"}
4 ]
5 }

2) /test_json.html内容
 1 <script src="/scripts/startup.js"></script>
 2 <script>
 3     $import("cn.site120.ajax.*");
 4     var url = "/data/test_json.js";
 5     var callback = function(response)
 6     {
 7         var p = eval("(" + response.responseText + ")");
 8         alert("length is : " + p.peoples.length);
 9         alert(p.peoples[0].name);
10         alert(p.peoples[1].name);
11     }
12     httpLoad(url , callback , null , null);
13 </script>


3) 打印结果
   length is : 2
   site120
   site120_2

-----------------------------------------------------------------------

可参考前一篇文章: Json技术一----- (原理)
JSON具体的数据规则,格式请参考官方网站
http://www.json.org/

posted on 2007-01-11 00:27 姜利阳 阅读(691) 评论(0)  编辑  收藏 所属分类: Javascript




标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-01-11 00:29 编辑过
 
 
相关链接:
网站导航: