Ekrem Tapan

Ekrem Tapan

  • NA
  • 967
  • 81.6k

DataTable convert to JSON Format

Aug 29 2016 2:45 AM
I have C# DataTable  in the following format: 
  1. ID    |  ParetCode|ChildCode| AttName | AttCode| 
  2. -------------------------------------------------
  3. 01    | 01        | 001    |  att1   | 3    |  
  4. 02    | 01        | 001    |  att2   | 456  |  
  5. 03    | 01        | 002    |  att1   | 87   |  
  6. 04    | 01        | 002    |  att0   | 65   |  
  7. 05    | 02        | 054    |  att1   | 54654|
How can I convert that into a Json object as follows?
  1. [  
  2.     {"id":"01","ParentCode":"01","ChildCode":001
  3.                                  {"AttName":"att1",
                                      "AttCode":3,
  4.                                   "AttName":"att2",
                                       "AttCode":456,
  5.                                    },
                                      "ChildCode":002
  6.                                              {
  7.                                              "AttName":"att1",
                                                 "AttCode":87,
  8.                                              "AttName":"att0",
                                                 "AttCode":65
  9.                                              }  
  10.     {"id":"05","ParentCode":"02","ChildCode":054
  11.                                                 {"AttName":"att1",
  12.                                                  "AttCode":"54654" 
  13.                                                 }
  14.     }  
  15. ]  

Answers (6)