private DataTable GetDataTable(JsonFields fields) { var table = new DataTable(); foreach (var field in fields[0].Fields) { table.Columns.Add(field.Id); } foreach (var jsonField in fields) { var row = table.NewRow(); foreach (DataColumn col in table.Columns) { try { var val = jsonField.Fields[col.ColumnName]?.Value.ToString(); if (int.TryParse(val, out var intVal)) { row[col] = intVal; } else { row[col] = jsonField.Fields[col.ColumnName]?.Value; } } catch { row[col] = jsonField.Fields[col.ColumnName]?.Value; } } table.Rows.Add(row); } return(table); }
public JsonObject() { Fields = new JsonFields(this); }