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 8786829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:44:09+00:00 2026-06-13T21:44:09+00:00

ok, so i have a class similar to this: public class Channel { public

  • 0

ok, so i have a class similar to this:

public class Channel
{
    public Guid Guid{get;set;}
    public string Title{get;set;}

    /* GOT A LOT MORE PROPERTIES IN THIS SPACE */

    public Guid Parent {get;set;}
    public List<Channel> Children{get;set;}
}

i also have a List<Channels> (with a total of about 650 Channels)

the ROOT channel contains about 6 channels and each of the channels contains, children and so on.

as you see in the code of Channel there are a lot of other properties,
which i don’t want to serialize IN THIS CASE. that is, all the Data Contracts are already defined in the base class, and i do not/can not change them just for this action.

so, what is my problem you ask?
i need to get a List<Channels> or List<NewType> to be serialized to JSON and maintain the Tree structure.

if it is not possible, at least, how would i serialize the List<Channels> to JSON maintaining the structure?

EDIT:
i am using Newtonsoft.Json

  • 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-13T21:44:10+00:00Added an answer on June 13, 2026 at 9:44 pm

    Personally I would suggest serializing the list to an array of Channels…consider the following JSON example:

    {
        "Channel": {
            "Guid": "27182d04-29d9-4760-86d5-484ba43cd9c6",
            "Title": "FooBar",
            "Parent": "52cfd532-6010-41c5-8fa9-f3bcbb97a630",
            "Children": [
                {
                    "Channel": {
                        "Guid": "27182d04-29d9-4760-86d5-484ba43cd9c6",
                        "Title": "FooBar",
                        "Parent": "52cfd532-6010-41c5-8fa9-f3bcbb97a630",
                        "Children": null
                    }
                },
                {
                    "Channel": {
                        "Guid": "27182d04-29d9-4760-86d5-484ba43cd9c6",
                        "Title": "FooBar",
                        "Parent": "52cfd532-6010-41c5-8fa9-f3bcbb97a630",
                        "Children": null
                    }
                },
                {
                    "Channel": {
                        "Guid": "27182d04-29d9-4760-86d5-484ba43cd9c6",
                        "Title": "FooBar",
                        "Parent": "52cfd532-6010-41c5-8fa9-f3bcbb97a630",
                        "Children": null
                    }
                }
            ]
        }
    }
    

    EDIT: Here is a little test code which will write this structure:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.Script.Serialization;
    
    namespace JSONTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Channel c = new Channel();
                c.Guid = Guid.NewGuid();
                c.Parent = Guid.NewGuid();
                c.Title = "FooBar";
                c.Children = new List<Channel>();
    
                Channel a = new Channel();
                Channel b = new Channel();
    
                a.Guid = Guid.NewGuid();
                b.Guid = Guid.NewGuid();
    
                a.Parent = Guid.NewGuid();
                b.Parent = Guid.NewGuid();
    
                a.Title = "FooBar_A";
                b.Title = "FooBar_B";
    
                c.Children.Add(a);
                c.Children.Add(b);
    
                /* Serialization happens here!! */
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string result = serializer.Serialize(c);
                Console.WriteLine(result);
                Console.Read();
            }
        }
    
        public class Channel
        {
            public Guid Guid { get; set; }
            public string Title { get; set; }
    
            /* GOT A LOT MORE PROPERTIES IN THIS SPACE */
    
            public Guid Parent { get; set; }
            public List<Channel> Children { get; set; }
        }
    }
    

    Here is the result of that test after being passed through JSONLint

    {
        "Guid": "0e72c12c-a7a1-461a-8b84-8b17023e2e2f",
        "Title": "FooBar",
        "Parent": "d0943246-1adc-4208-bb3b-1249ffe5e7b4",
        "Children": [
            {
                "Guid": "1cf413be-d6b5-405e-8308-7c6dfe817f9a",
                "Title": "FooBar_A",
                "Parent": "ecf14fce-c97d-46f5-890b-bab8ff99fb4a",
                "Children": null
            },
            {
                "Guid": "bd96e6d3-f247-4a0d-9147-92da19793e97",
                "Title": "FooBar_B",
                "Parent": "5cd3e765-23c2-4145-8b45-9964a7c66c54",
                "Children": null
            }
        ]
    }
    

    VALID JSON!

    EDIT: One thing I have noticed is that JavaScriptSerializer does not parse “Channel”, since the whole object is of type Channel and each object in “Children” is of type Channel. If you were to pass this JSON through the Deserialize method, if should build this back into a C# structure with all JSON persisted data.

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

Sidebar

Related Questions

i have a class similar to this: public class Channel { public string Title
I Have something similar to this setup: public class Base { public String getApple()
I have a class Similar to this public class Model { public TimeSpan Time1
I have a model similar to this: public class myModel { public ClassA ObjectA
I have a constructor method similar to this: public class Foo { public Foo
I have documents similar to this in RavenDB: public class MyClass { ... public
I have a structure similar to this: class OuterClass{ AnimatorListener sth; public OuterClass(){ sth
I have a similar code snippet like this class Search { public function search($for,
I have a class like this: public class Data { public string Name {
I have some code similar to this: public class Main { private static abstract

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.