如何转换成JSON数据表?转换成、数据表、JSON

2023-09-02 02:05:27 作者:狂拽酷霸叼

有谁知道如何JSON字符串从asp.net转换成数据表?我来了解反序列化,它需要的类,我只是想在数据表作为返回。谁能告诉我怎么把它转换为数据表?

Does anyone know how to convert a json string into DataTable from asp.net? I came to know about the Deserialize, it needs the class, I just want the datatable as returned. Can anyone tell me how to convert it to datatable?

推荐答案

假设你的JSON字符串是对象的列表,每个对象都将对应一个行中的数据表,即:

Assuming that your JSON string is a list of objects, each object will correspond to a row in the DataTable, viz:

    public DataTable DerializeDataTable()
    {
        const string json = @"[{""Name"":""AAA"",""Age"":""22"",""Job"":""PPP""},"
                           + @"{""Name"":""BBB"",""Age"":""25"",""Job"":""QQQ""},"
                           + @"{""Name"":""CCC"",""Age"":""38"",""Job"":""RRR""}]";
        var table = JsonConvert.DeserializeObject<DataTable>(json);
        return table;
    }

这需要 Json.NET框架。

如果你的JSON结构是不同的,请张贴。顺祝商祺。

If your JSON structure is different please post it. Best Regards.