I have a JSON
string where records can change. I'm using public partial classes
for every level I have in my JSON string. I'm copying it to a DataTable
since I need it in my SQL-Server. I'm calling JSON like this:
StringReader sr = new StringReader(json);
Newtonsoft.Json.JsonTextReader readera = new JsonTextReader(sr);
object result = (Welcome)jsona.Deserialize(readera,typeof(Welcome));
Welcome w = (Welcome)result;
DataTable da = w.Result.Records.ToDataTable();
So for example, my JSON
can contain:
ID,Name,Value
But other JSON
might contain:
ID,Address,City,PostcalCode
My Class looks like this now:
public partial class Record
{
[JsonProperty("Col1")]
public DateTimeOffset Col1 { get; set; }
[JsonProperty("Col2")]
public long Col2 { get; set; }
[JsonProperty("Col3")]
public DateTimeOffset Col3 { get; set; }
[JsonProperty("Col4")]
public long Col4 { get; set; }
[JsonProperty("Col5")]
public string Col5 { get; set; }
How would I make this Dynamic? I really don't have a clue.