How to convert json into datatable?

Assuming that your JSON string is a list of objects, each object will correspond to a row in the DataTable, viz:

    public DataTable DerializeDataTable()
    {
        const string json = @"[{""Name"":""AAA"",""Age"":""22"",""Job"":""PPP""},"
                           + @"{""Name"":""BBB"",""Age"":""25"",""Job"":""QQQ""},"
                           + @"{""Name"":""CCC"",""Age"":""38"",""Job"":""RRR""}]";
        var table = JsonConvert.DeserializeObject<DataTable>(json);
        return table;
    }

This requires the Json.NET framework.

If your JSON structure is different please post it. Best Regards.

Leave a Comment