javascript - Create complex json from datatable c# -


i have 3 datatables in dataset. table has 1 many relationship b , c. want create json below using linq in c#. can please me? in advance guide me or provide me input question.

{     "a": [         {             "id": "0001",             "type": "donut",             "name": "cake",             "ppu": 0.55,             "b": [                 {                     "id": "1001",                     "type": "regular"                 }             ],             "c": [                 {                     "id": "5001",                     "type": "none"                 },                 {                     "id": "5002",                     "type": "glazed"                 }             ]         }     ],     "a": [         {             "id": "0002",             "type": "cupcake",             "name": "cake",             "ppu": 2.43,             "b": [                 {                     "id": "1001",                     "type": "regular"                 }             ],             "c": [                 {                     "id": "5001",                     "type": "none"                 },                 {                     "id": "5002",                     "type": "glazed"                 }             ]         }     ] } 

first of all, have create these classes,

public class result {     public list<tablea> { get; set; } } public class tablea {     public tablea()     {           b = new list<tableb>();           c = new list<tablec>();     }     public string id { get; set; }     public string type { get; set; }     public string name { get; set; }     public float ppu { get; set; }     public virtual list<tableb> b { get; set; }     public virtual list<tablec> c { get; set; } }  public class tableb {     public string id { get; set; }     public string type { get; set; } } public class tablec {     public string id { get; set; }     public string type { get; set; } } 

after then, store values in result object of result class , serialize using newtonsoft serializer mentioned below:

result result; jsonconvert.serializeobject(result);  

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -