<script type="text/javascript" src="jquery-1.9.1.js"></script> <script type="text/javascript"> function test() { $.ajax({ type: "get", cache: false, url: "../../ajax/Task.aspx", data: 'id =1', // URL后面参数 success: function (json) { json = eval("(" + json + ")"); $.each(json, function (i, item) { alert(parseInt(item.iname), parseInt(item.iid)); }); }, error: function (msg) { alert("错误:" + msg); } }); } </script>
后台代码: public void ProcessRequest(HttpContext context)//只是大概个例子 为了学习 { context.Response.ContentType = "application/json"; string[] Arraya = new string[] { "张三", "李四", "王二", "赵五" }; string returns = ""; returns = "{"people":["; for (int i = 0; i < Arraya.Length; i++) { returns += "[{"iname":"" + Arraya[i] + "","iid":"001"}]" + (i != (Arraya.Length - 1) ? "," : ""); } returns += "]};"; context.Response.Write(returns);//返回之后 就是上面js里直接定义的json格式 }