How to loop through JSON GET result?

How to loop through JSON GET result?

hi,

i want to consume a JSON Webservice which return the following:

  1. {"GetDataResult":[{"firstname":"firstname1","lastname":"lastname1"},{"firstname":"firstname2","lastname":"lastname2"}]}

I want to loop through the data and put it for example in an HTML Table.

I tried the following:

  1.  $(document).ready(function () {
                var JSONService = "/_vti_bin/JSONWebService/Service1.svc/GetData/ae";
                $.ajax({
                    type: "GET",
                    contentType: "application/json",
                    dataType: "json",
                    url: JSONService
                })
                .done(function (response) {
                    $.each(response, function (index, value) {








  2.                     console.log(response.firstname);
                        console.log(JSON.stringify(response));
                        console.log(response.GetDataResult.lastname);

  3.                 })
                })
                .fail(function (jqXHR, textStatus) { alert("error" + textStatus); })
                .always(function () { alert("complete"); });


But at console.log(response.firstname); and at console.log(response.GetDataResult.lastname); i get UNDEFINED! I see on the net that people are using the objects like response.dataresult.propertyname to return the info, but in my case it isn't working!

The desired output should be:

firstname1     lastname1
firstname2     lastname2

 

Whats wrong with my code?

console.log(JSON.stringify(response)); gives me the following

{"GetDataResult":[{"firstname":"firstname1","lastname":"lastname1"},{"firstname":"firstname2","lastname":"lastname2"}]}

 

regards

Yavuz