【发布时间】:2016-02-26 20:05:22
【问题描述】:
我想将此数据转换为以下格式的 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# 也很好。
【问题讨论】:
-
首先根据您的要求将此数据集转换为实体列表,然后将其序列化。
-
我的问题不是“如何将数据集序列化为 JSON”。我的问题指定“使用 VB.Net 到 JSON 的数据集”。这意味着我需要编写一个代码,该代码从数据集中获取行并为其属性分配三个不同的类,然后对其进行序列化。我无法迭代嵌套对象。
-
使用LINQ或者foreach遍历所有的行列,准备一个需要序列化的实体列表。