[Solved] parse JSON using json.net c# [closed]


Step 1. Make some models (or Plain Old C# Classes if you like) to deserialize your json into (generated by http://json2csharp.com/) – this is generally a little bit easier to work with that straight up json:

public class Customise
{
    public string name { get; set; }
    public int id { get; set; }
    public string price { get; set; }
}

public class Cart
{
    public int itemId { get; set; }
    public string itemname { get; set; }
    public string qty { get; set; }
    public string price { get; set; }
    public List<Customise> customise { get; set; }
    public string comment { get; set; }
    public string linetotal { get; set; }
}

public class TableData
{
    public int tableId { get; set; }
    public int userId { get; set; }
    public int branchId { get; set; }
    public List<Cart> cart { get; set; }
    public string total { get; set; }
}

Step 2. Add Json.NET dependency to your project via NuGet package manager

Step 3. Deserialize your JSON string as such to get a object instance with all values set (I named your root object TableData, this can obviously be changed):

var data = JsonConvert.DeserializeObject<TableData>(jsonString);

Now all the json data has been set inside the data object.

1

solved parse JSON using json.net c# [closed]