我有以下数据的数据集: 数据集,以JSON使用C#/ VB.Net
我想这个数据转换成JSON的格式如下:
{
"Resource": [
{
"resourceID": "1",
"resourceName": "Jonathan",
"Customer": [
{
"customerID": "1",
"firstName": "Alec",
"lastName": "Stewart",
"Appointments": [
{
"appointmentID": "1",
"startDate": "01-01-2015",
"endDate": "01-01-2015"
},
{
"appointmentID": "2",
"startDate": "01-01-2015",
"endDate":"01-01-2015",
}
]
},
{
"customerID": "2",
"firstName": "Chris",
"lastName": "Douglas",
"Appointments": [
{
"appointmentID": "3",
"startDate": "01-01-2015",
"endDate": "01-01-2015",
}
]
}
]
},
{
"resourceID": "2",
"resourceName": "Matthew",
"Customer": [
{
"customerID": "3",
"firstName": "Shirley",
"lastName": "Graham",
"Appointments": [
{
"appointmentID": "4",
"startDate": "01-01-2015",
"endDate": "01-01-2015",
},
{
"appointmentID": "5",
"startDate": "01-01-2015",
"endDate": "01-01-2015"
}
]
},
{
"customerID": "4",
"firstName": "Ricardo",
"lastName": "Powell",
"Appointments": [
{
"appointmentID": "6",
"startDate": "01-01-2015",
"endDate": "01-01-2015"
}
]
}
]
}
]
}
有什么更快的方式,我可以在VB.Net中使用它直接转换为JSON?我是否应该创建类并列出并迭代数据集来创建嵌套类的对象,然后对其进行序列化,或者以不同的方式实现它?有人能告诉我有关将数据集序列化为JSON的方式吗?我对C#也很好。
第一转换这个d按照您的要求在实体列表中按照序列化。 – Arshad
我的问题不是“如何序列化数据集到JSON”。我的问题指定“使用VB.Net的数据集到JSON”。这意味着我需要编写一个代码,该代码从数据集中获取行并为其分配三个不同的类,然后对其进行序列化。我无法迭代嵌套对象。 – user1640256
使用LINQ或foreach遍历所有行和列,并准备需要序列化的实体列表。 – Arshad