如何转换成JSON数据表? [英] How to convert json into datatable?
本文介绍了如何转换成JSON数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何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.
这篇关于如何转换成JSON数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文