开发者

how to get values of object?

开发者 https://www.devze.com 2023-01-26 07:23 出处:网络
how do i grab the values of a Person[] object? below is my server side code: public Person[] GetPersonList()

how do i grab the values of a Person[] object?

below is my server side code:

public Person[] GetPersonList()
{
   //impl code....
   return new Person[0];
}

and my client code:

  $("#btn3").click(function (event) {
                $.getJSON(url', { },
                function (data) {
                    alert(data.Name);
                });
            });

i am getting this result in Firebug:

jsonp1290528639946( [{"Active":true,"Description":"I开发者_JAVA百科nitial Test","Id":"1","Name":"Test2010","EndDate":"\/Date(-62135578800000-0500)\/","StartDate":"\/Date(1280635200000-0400)\/"}] );


You're returning an array, not just an object, so it would need to be:

$("#btn3").click(function (event) {
  $.getJSON('url', { }, function (data) {
     alert(data[0].Name);
  });
});

Or for example looping through them:

$("#btn3").click(function (event) {
  $.getJSON('url', { }, function (data) {
    $.each(data, function(i, person) {
      alert(person.Name);
    });
  });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号