我想将此数据转换为以下格式的 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#。
最佳答案
如前所述,newtonsoft是一个真正的美女。你可以这样做:
string json = JsonConvert.SerializeObject(yourdataset, Formatting.Indented);
关于c# - 使用 C#/VB.Net 将数据集转换为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33892689/