.net 如何将我的JSON转换为DataTable?

.net 如何将我的JSON转换为DataTable?,.net,.net,我有下面的JSON,我想将其转换为Datatable,我尝试了下面的代码,但它出错了。有人能帮我吗 [ { "Attributes": [ { "ProductId": 100, "AttributeCode": "Code", "AttributeValue": "xyz"

我有下面的JSON,我想将其转换为Datatable,我尝试了下面的代码,但它出错了。有人能帮我吗

[
        {
            "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);

它可以工作,但不确定如何访问每个对象或值并转换为datatable

没关系,我尝试了下面的一行,它成功了。希望它能帮助别人

List<RootObject> rt = JsonConvert.DeserializeObject<List<RootObject>>(json);
List rt=JsonConvert.DeserializeObject(json);
谷歌it或检查答案可能重复。
List<RootObject> rt = JsonConvert.DeserializeObject<List<RootObject>>(json);