嵌套的JSON到数据表 [英] Nested JSON to datatable
本文介绍了嵌套的JSON到数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Chart类如下:
< pre> private Int32 _id = 0 ;
public Int32 id
{
get { return _id; }
set {_ id = value ; }
}
private string _name = 串跨度> .Empty;
public string name
{
get { return _name; }
set {_ name = value ; }
}
private Int32 _ParentID = 0 跨度>;
public Int32 ParentID
{
get { return _ParentID; }
set {_ ParentID = value ; }
}
private IEnumerable< clsChart> _children = null ;
public IEnumerable< clsChart>子女
{
获取 {返回 _children; }
set {_ children = value ; }
}
我有一个我想要的JSON字符串转换为DataTable:
dtChart = new DataTable();
dtChart.Columns.Add(id);
dtChart.Columns.Add(parentid);
JSON字符串:
[
{
id: 1,
children:[
{
id: 2,
children:[
{
id: 4,
children:[
{
id: 7
}
]
},
{
id: 6
}
]
},
{
id: 3,
children:[
{
id: 5
},
{
id: 8
}
]
}
]
}
]
我尝试了什么:
我试过这个链接:
asp.net - 如何将JSON对象转换为自定义C#对象? - 堆栈溢出 [ ^ ]
解决方案
Google(或者我的情况下,DuckDuckGo)已满链接:
json到DuckDuckGo的数据表 [ ^ ]
I have a Chart class as following:
<pre> private Int32 _id = 0;
public Int32 id
{
get { return _id; }
set { _id = value; }
}
private string _name = string.Empty;
public string name
{
get { return _name; }
set { _name = value; }
}
private Int32 _ParentID = 0;
public Int32 ParentID
{
get { return _ParentID; }
set { _ParentID = value; }
}
private IEnumerable<clsChart> _children = null;
public IEnumerable<clsChart> children
{
get { return _children; }
set { _children = value; }
}
I have a JSON string which I want to convert to DataTable:
dtChart = new DataTable(); dtChart.Columns.Add("id"); dtChart.Columns.Add("parentid");
JSON String:
[
{
"id": "1",
"children": [
{
"id": "2",
"children": [
{
"id": "4",
"children": [
{
"id": "7"
}
]
},
{
"id": "6"
}
]
},
{
"id": "3",
"children": [
{
"id": "5"
},
{
"id": "8"
}
]
}
]
}
]
What I have tried:
I have tried this link:
asp.net - How to Convert JSON object to Custom C# object? - Stack Overflow[^]
解决方案
Google (or in my case, DuckDuckGo) is FULL of links:
json to datatable at DuckDuckGo[^]
这篇关于嵌套的JSON到数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文