Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6611687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:07+00:00 2026-05-25T20:00:07+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:00:07+00:00Added an answer on May 25, 2026 at 8:00 pm

    You could do some linq grouping against the array

        var peeps = from person in people 
            group person by person.name into bucket 
            select new { name = bucket.Key, count = bucket.Count() };
    

    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. :

    class Guy
        {
            public int age; public string name;
            public Guy( int age, string name ) {
                this.age = age;
                this.name = name;
            }
    
        }
    
        class Program
        {
            static void Main( string[] args ) {
                var GuyArray = new Guy[] { 
                new Guy(22,"John"),new Guy(25,"John"),new Guy(27,"John"),new Guy(29,"John"),new Guy(12,"Jack"),new Guy(32,"Jack"),new Guy(52,"Jack"),new Guy(100,"Abe")};
    
            var peeps = from f in GuyArray group f by f.name into g select new { name = g.Key, count = g.Count() };
    
                foreach ( var record in peeps ) {
                    Console.WriteLine( record.name + " : " + record.count );
                }
    
            }
        }
    

    Will emit:

    John : 4
    Jack : 3
    Abe : 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single dimensional array of items declared and initialized as: string[] SubDirectorylist
How can I store arrays in single array? e.g. I have four different arrays,
Say I have an array of arbitrary size holding single characters. I want to
I have a single spool mbox file that was created with evolution, containing a
I’m new to android,I have an activity class which fetches Json string from url
lets say I have a String like this [{ name : Ronald , firstname
[I have some code to create a JSON array. In this code I am
I have a PHP single dimension array, when using the json_encode function on that
I have a json object in my JavaScript file containing qs: {} which when
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.