I have the below JSON, which i want to convert to Datatable, i am tried the below code, but it errors out. Can someone help me with this
[
{
"Attributes": [
{
"ProductId": 100,
"AttributeCode": "Code",
"AttributeValue": "xyz"
},
{
"ProductId": 100,
"AttributeCode": "PID",
"AttributeValue": "71"
},
{
"ProductId": 100,
"AttributeCode": "STATUS",
"AttributeValue": "Active"
},
{
"ProductId": 100,
"AttributeCode": "Type",
"AttributeValue": "Offering"
}
],
"MasterId": 100,
"ProductName": "Core Credit Services"
}
]
string path = @"c:\data\test.txt";
if (!File.Exists(path))
{
MessageBox.Show("File does not exist");
return;
}
string json = File.ReadAllText(path);
JArray j = JsonConvert.DeserializeObject<JArray>(json);
RootObject rt = JsonConvert.DeserializeObject<RootObject>(json);
When i try with
dynamic obj = JsonConvert.DeserializeObject(json, typeof(object));
it works but not sure how to access each object or value and convert to datatable