parsing JSON format file in c# -


greeting,

i finding difficulty in parsing json format file in c# having array of highly nested objects looks follows

[     {         "id": "0001",         "type": "donut",         "name": "cake",         "ppu": 0.55,         "batters":             {                 "batter":                     [                         { "id": "1001", "type": "regular" },                         { "id": "1002", "type": "chocolate" },                         { "id": "1003", "type": "blueberry" },                         { "id": "1004", "type": "devil's food" }                     ]             },         "topping":             [                 { "id": "5001", "type": "none" },                 { "id": "5002", "type": "glazed" },                 { "id": "5005", "type": "sugar" },                 { "id": "5007", "type": "powdered sugar" },                 { "id": "5006", "type": "chocolate sprinkles" },                 { "id": "5003", "type": "chocolate" },                 { "id": "5004", "type": "maple" }             ]     },     {         "id": "0002",         "type": "donut",         "name": "raised",         "ppu": 0.55,         "batters":             {                 "batter":                     [                         { "id": "1001", "type": "regular" }                     ]             },         "topping":             [                 { "id": "5001", "type": "none" },                 { "id": "5002", "type": "glazed" },                 { "id": "5005", "type": "sugar" },                 { "id": "5003", "type": "chocolate" },                 { "id": "5004", "type": "maple" }             ]     },     {         "id": "0003",         "type": "donut",         "name": "old fashioned",         "ppu": 0.55,         "batters":             {                 "batter":                     [                         { "id": "1001", "type": "regular" },                         { "id": "1002", "type": "chocolate" }                     ]             },         "topping":             [                 { "id": "5001", "type": "none" },                 { "id": "5002", "type": "glazed" },                 { "id": "5003", "type": "chocolate" },                 { "id": "5004", "type": "maple" }             ]     } ] 

i looking solution "id", "type","name", "ppu" private members of class , "batters" , "topping" dictionary members. kindly suggest me better way in getting parsed.

thank you.

following class structure parse json c# object.

public class batter {     public string id { get; set; }     public string type { get; set; } }  public class batters {     public list<batter> batter { get; set; } }  public class topping {     public string id { get; set; }     public string type { get; set; } }  public class rootobject {     public string id { get; set; }     public string type { get; set; }     public string name { get; set; }     public double ppu { get; set; }     public batters batters { get; set; }     public list<topping> topping { get; set; } } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -