Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Chart class as following:

C#
<pre>  private Int32 _id = 0;
        public Int32 id
        {
            get { return _id; }
            set { _id = value; }

        }
            private string _name = string.Empty;
        public string name
        {
            get { return _name; }
            set { _name = value; }
        }
        private Int32 _ParentID = 0;
        public Int32 ParentID
        {
            get { return _ParentID; }
            set { _ParentID = value; }

        }
        private IEnumerable<clsChart> _children = null;
        public IEnumerable<clsChart> children
        {
            get { return _children; }
            set { _children = value; }

        }



I have a JSON string which I want to convert to DataTable:

dtChart = new DataTable();
dtChart.Columns.Add("id");
dtChart.Columns.Add("parentid");


JSON String:

JavaScript
[
{
  "id": "1",
  "children": [
    {
      "id": "2",
      "children": [
        {
          "id": "4",
          "children": [
            {
              "id": "7"
            }
          ]
        },
        {
          "id": "6"
        }
      ]
    },
    {
      "id": "3",
      "children": [
        {
          "id": "5"
        },
        {
          "id": "8"
        }
      ]
    }
  ]
}
]


What I have tried:

I have tried this link:

asp.net - How to Convert JSON object to Custom C# object? - Stack Overflow[^]
Posted
Updated 28-Mar-19 23:42pm

1 solution

Google (or in my case, DuckDuckGo) is FULL of links:

json to datatable at DuckDuckGo[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900