How can i iterate the following list and print its values?
public class DummyVersions
{
public List<string> Version { get; set; }
}
[WebMethod]
public static DummyVersions GetDummyVersions()
{
DummyVersions dummyversions = new DummyVersions
{
Version = new List<string>
{
"1.1.0",
"1.1.1",
"1.1.2",
"1.1.3",
"1.1.4",
"1.1.5",
}
};
return dummyversions;
}
$.ajax({
type: "POST",
url: "ManagerBaseKit.aspx/GetDummyVersions",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$.each(result, function (i, val) {
alert(); // ??? here i want to print all version one by one
});
}
});
With the
WebMethodyour resonse is automatically converted to json by ASP.NET, so you can iterate through your versions using the code below:It can be
result.d.Versionorresult.Versiondepending on your ASP.NET version more info about that can be found here: A breaking change between versions of ASP.NET AJAX