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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:39:30+00:00 2026-06-06T10:39:30+00:00

I’ve used this useful JQuery function that serializes nested elements. the problem is how

  • 0

I’ve used this useful JQuery function that serializes nested elements. the problem is how to deserialise it using c#.

the following code gives

No parameterless constructor defined for type of ‘System.Collections.Generic.IList`

string json = @"{""root"":{""id"":""main"",""text"":""150px"",""children"":
    [{""id"":""divcls"",""text"":""50px"",""children"":
    [{""id"":""qs1"",""text"":""0px"",""children"":[]}]},
     {""id"":""divcls2"",""text"":""50px"",""children"":[]},
     {""id"":""divcls3"",""text"":""50px"",""children"":[]}]}}";

IList<Commn.main1> objs = new JavaScriptSerializer()
    .Deserialize<IList<Commn.main1>>(json);
string blky = "";

foreach (var item in objs)
{
    blky += item.id;
}
Label1.Text = Convert.ToString(blky);

public class main1
{
    public string id { get; set; }
    public string text { get; set; }
    public sub1 children { get; set; }
}

public class sub1
{
    public string Qid { get; set; }
    public string Qval { get; set; }
}

My Json is only 2 Levels deeep If the solution is recursive how could i know the depth of the element

By the way can a class reference itself like this

public class main1
{
    public string id { get; set; }
    public string text { get; set; }
    public  main1 children { get; set; }
}
  • 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-06T10:39:32+00:00Added an answer on June 6, 2026 at 10:39 am

    First of all, yes a class can reference itself. In your case, you would need to have a main1[] property to represent its children.

    public class main1 
    {    
        public string id { get; set; } 
        public string text { get; set; }
        public main1[] children { get; set; } 
    }
    

    Next, your json string contains not only a main1 object, but also some other object with a “root” property of type main1. It’s perfectly fine, but then you need another class to deserialize into :

    public class foo
    {
        public main1 root { get; set; }
    }
    

    You should then be able to use the Deserialize method to get an instance of foo :

    var myFoo = new JavaScriptSerializer().Deserialize<foo>(json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
I used javascript for loading a picture on my website depending on which small

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.