<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/json_parse.js"></script>
<script type="text/javascript">
$(function(){
//1.返回数据类型 dataType: 'json'
//2.发送到服务器的数据类型 contentType: "application/json",
//3.传递的数据格式 为空时:data: "{}", 不为空时:data: "{username:\"Lee\"}",
//4.返回的json数据格式 {"d":"你希望返回的json数据"} , 多条数据:{"d":"[{},{}]"} , 单条:{"d":"{}"}
//5.转换成json数据 json_parse(msg.d) ,msg.d为你希望获得的json数据的字符串形式,利用json_parse(msg.d)转换为json类型
$.ajax({
async:true,
type:"POST",
contentType: "application/json",
dataType: 'json', //返回数据类型
url: "2.asmx/GetList1",
data: "{}",
//data: {username:username},
success: function(msg) {
//webservice返回的json数据格式为 {"d":"你希望返回的数据"} 例如: {"d":"[{},{}]"} 或 {"d":"{}"}
var responseText=json_parse(msg.d);
for(i=0;i<responseText.length;i++)
{
$("#rt").append(responseText[i].name+"__"+responseText[i].age+"<br/>");
}
},
error: function(){alert("error");}
});
$.ajax({
async:true,
type:"POST",
contentType: "application/json",
dataType: 'json', //返回数据类型
url: "2.asmx/GetList2",
data: "{username:\"Lee\"}",
//data: {username:username},
success: function(msg) {
//webservice返回的json数据格式为 {"d":"你希望返回的数据"} 例如: {"d":"[{},{}]"} 或 {"d":"{}"}
var responseText=json_parse(msg.d);
$("#rt2").append(responseText.name+"__"+responseText.age+"<br/>");
},
error: function(){alert("error");}
});
});
</script>
<div id="rt">
</div>
<div id="rt2">
</div>

c#
[WebMethod]
public string GetList1()
{
Context.Response.Cache.SetNoStore();
StringBuilder returnValue = new StringBuilder();
returnValue.Append("[");
returnValue.Append("{\"name\":\"Lee\",\"age\":\"28\"},");
returnValue.Append("{\"name\":\"Lucy\",\"age\":\"25\"}");
returnValue.Append("]");
return returnValue.ToString();
}
[WebMethod]
public string GetList2(string username)
{
Context.Response.Cache.SetNoStore();
StringBuilder returnValue = new StringBuilder();
returnValue.Append("{\"name\":\"" + username + "\",\"age\":\"25\"}");
return returnValue.ToString();
}