-2

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

SSK
  • 783
  • 3
  • 18
  • 42
  • Possible duplicate of [How to convert json into datatable?](http://stackoverflow.com/questions/7641004/how-to-convert-json-into-datatable) – Ash Jun 16 '16 at 06:30
  • Google it or check [these](http://stackoverflow.com/questions/11981282/convert-json-to-datatable) answers. – neer Jun 16 '16 at 06:31

1 Answers1

-1

Never mind, i tried with the below line and it worked. Hope it will help others

List<RootObject> rt = JsonConvert.DeserializeObject<List<RootObject>>(json);
SSK
  • 783
  • 3
  • 18
  • 42