0
    Json Object List.
-------------------------
        var params = new Object(); 
        params.Id = personId;
        params.cls = Class;

 $.ajax({
                type: "POST",
                dataType: "json",
                data: $.toJSON(params),
                contentType: "application/json",
                url: "../OtpWebService.asmx/GetStudentDetails",

                         alert(response.d);

                }
            });
The out-put, when i do alert(response.d); is given below.
actually this is an json object returned by a above code from c#.

            [
                {"Name":"Nthal","Class":3,"SubjectName":"English "},
                {"Name":"Mishal","Class":4,"SubjectName":"Grammer"},
                {"Name":"Sanjeev","Class":3,"SubjectName":"Social"},
                {"Name":"Michal","Class":5,"SubjectName":"Gk"},
            ]

if i try alert(response); the result will be just --> [object] [object]. How can i iterate through each element in this object list and and print through document.write..?

  • It's an array. How do you iterate through an array?? – Hot Licks Sep 26 '13 at 15:32
  • possible duplicate of [Loop through array in JavaScript](http://stackoverflow.com/questions/3010840/loop-through-array-in-javascript) – Eric Andres Sep 26 '13 at 15:33
  • Please *look* at your question and consider whether it's easy to read. You're using a lot of incorrect markup there. Just read the formatting tips (the "Ask a Question" page showed them **right next to** the editing area). – T.J. Crowder Sep 26 '13 at 16:47

1 Answers1

1

The following code snippet may help:

var dataItem = [
    {"Name":"Nthal","Class":3,"SubjectName":"English "},
    {"Name":"Mishal","Class":4,"SubjectName":"Grammer"},
    {"Name":"Sanjeev","Class":3,"SubjectName":"Social"},
    {"Name":"Michal","Class":5,"SubjectName":"Gk"},
]

for(x in dataItem)
{
alert(dataItem[x].Name);
alert(dataItem[x].Class);
alert(dataItem[x].SubjectName);
}
Christopher
  • 58
  • 1
  • 6