i have an object which holds a user name and job count, which then is inserted into a list. (from a datatable)
Assuming the code below is the right way to go about this, how do i access these data elements in javascript?
class:
public class thePeople
{
public string Name { get; set; }
public string Calls { get; set; }
public thePeople(string n, string c)
{
Name = n;
Calls = c;
}
}
then the code using the class:
var thosePeople = new List<thePeople>();
StringBuilder Qry = new StringBuilder();
Qry.Append("SELECT Count(Job_Id) as TotalJobs, User_Name,User_Id, jobstatus ");
Qry.Append("FROM Jobs, Users ");
Qry.Append("WHERE Jobs.jobstatus like 'o' AND Users.deleted = '0' AND Jobs.Next_User_Id = Users.User_Id ");
Qry.Append("GROUP BY User_Name");
DataTable dt = new DataTable();
dt = OMALibrary.OMADAL.Execute.PerCustomer.Query(Qry.ToString(), OMALibrary.OMADAL.Enumerators.TypeOfServers.Helpdesk, theCustomer);
for (int x = 0; x <= dt.Rows.Count - 1; x++)
{
thosePeople.Add(new thePeople(dt.Rows[x]["User_Name"].ToString(), dt.Rows[x]["Total_Jobs"].ToString()));
}
return JsonConvert.SerializeObject(thosePeople);
When i did this before for a “single row” object, I’d just use:
var users = jQuery.parseJSON(response.d)
then just access it by typing:
users.Name; users.Calls;
You’ll need to look at the serialized result to see what it looks like. Since you’re serializing a
List, it probably comes through as an array:…and so you’d access the elements as
Or loop through: