I have a web method in ASP.net which it's output is an ArrayList and read cities from databse. this web method is called using jquery.
$.ajax(
    { url: "../AjaxServices/StateCity.asmx/showcity",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        data: '{s: ' + $('#<%=DpState.ClientID%>').val() + '}',
        success: function(data) {
}
I wanna know how to loop through data,开发者_StackOverflow社区 because the data is object.
I knew about 
jQuery.each( collection, callback(indexInArray, valueOfElement) )
but doesn't work
When you call an ASP.Net WebMethod using AJAX, it returns an object with a d property containing your data.
If your WebMethod returns a collection, you can write
$.each(data.d, function(index, obj) { ... });
Slaks answer is great a ndI found a solution base on SLaks answer, so I'll share it here:
just take care about Value and Text they're case sensitive.
success: function(data) { 
                $.each(data.d, function() {   
                  alert(this['Value'] + ':' + this['Text']);                 })             } 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论