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

  • Home
  • SEARCH
  • 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 8735447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:03:37+00:00 2026-06-13T10:03:37+00:00

i have 2 class: class Employee { string name; string age; } class Departments

  • 0

i have 2 class:

class Employee
{
    string name;
    string age;
}

class Departments
{
    string branch;
    Employee A;
}

Declare new list:

List<Departments> lstDp = new List<Departments>();

after get/set and Add Employee into the list … i have a LIST of Departments include Employee info. And then:

string json = JsonConvert.SerializeObject(lstDp, Newtonsoft.Json.Formatting.Indented);

but the output JSON string only contain element “branch”. What’s wrong with this? I want the output like this:

[
  {
    "branch": "NY",
    "Employee": {
        "name": "John Smith",
        "age": "29",
    }
  }
]
  • 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-06-13T10:03:38+00:00Added an answer on June 13, 2026 at 10:03 am

    The problem can be that some of class members is private. Just tested:

    class Employee
    {
        public string Name { get; set; }
        public string Age { get; set; }
    }
    
    class Departments
    {
        public string Branch { get; set; }
        public Employee Employee { get; set; }
    }
    

    And

    var lstDp = new List<Departments> {
                new Departments {
                    Branch = "NY",
                    Employee = new Employee { Age = "29", Name = "John Smith" }
                }
            };
    var json = JsonConvert.SerializeObject(lstDp, Formatting.Indented);
    

    Works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Employee { friend string FindAddr( list<Employee> lst,string name
i have this Class public Class Employee { String name; List<Address> listOfAddress; } public
Assume I have a business object like this, class Employee { public string name;
Given the following classes: class Department { public String Name { get; set; }
I have class with back reference: public class Employee : Entity { private string
I am a grails beginner. i have a 2domain class class Employee { String
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following: MODEL.PY LIST = (('Manager', 'Manager'),('Non-Manager', 'Non-Manager'),) class Employee(models.Model): fname =
Say I have a class, User: public class User { private String name; private
For C# properties, I can do this: public class Employee{ public string Name {

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.