Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 978 Bytes

DeserializeDataSet.md

File metadata and controls

42 lines (34 loc) · 978 Bytes

Deserialize a DataSet

This sample deserializes JSON to a System.Data.DataSet.

var json = """
    {
      'Table1': [
        {
          'id': 0,
          'item': 'item 0'
        },
        {
          'id': 1,
          'item': 'item 1'
        }
      ]
    }
    """;

var settings = new JsonSerializerSettings();

settings.AddDataSetConverters();
var dataSet = JsonConvert.DeserializeObject<DataSet>(json, settings);

var dataTable = dataSet.Tables["Table1"];

Console.WriteLine(dataTable.Rows.Count);
// 2

foreach (DataRow row in dataTable.Rows)
{
    Console.WriteLine($"{row["id"]} - {row["item"]}");
}

// 0 - item 0
// 1 - item 1

snippet source | anchor