如何将json转换为数据表? [英] How to convert json into datatable?

查看:28
本文介绍了如何将json转换为数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何将 json 字符串从 asp.net 转换为 DataTable?我开始了解反序列化,它需要类,我只想要返回的数据表.谁能告诉我如何将其转换为数据表?

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 字符串是一个对象列表,每个对象都会对应 DataTable 中的一行,即:

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.

这篇关于如何将json转换为数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆