I have a single array json string containing data:
[{"Name":"John","Age":"22"}, {"Name":"Jack","Age":"56"}, {"Name":"John","Age":"82"}, {"Name":"Jack","Age":"95"}]
I have deserialized the data and have successfully written the data to jquery datatables. However i would now like to add a column in the datatable to contain the count of names that are john and names that are jack all in one column. I can get the individual counts by saying the following in a loop:
if (people[i].Name == "John")
{
name_count++;
}
if (people[i].Name == "Jack")
{
name_count2++;
}
How do i get this data to display in One Column that matches either the row containing the name jack or john? I am using C#. Thanks in advance
You could do some linq grouping against the array
This will create an enumerable anonymous type with name and count properties that you can iterate over to get the name and count of the names, e.g. :
Will emit: