I'm trying to serialize C# DataTable using Newtonsoft JsonConverter
Code :
JsonConvert.SerializeObject(dt); //dt is DataTable
Result I got is :
[
{
"Name": "Tiger Nixon",
"Position": "System Architect",
"Address": "Edinburgh",
"No": "5421"
},
{
"Name": "Garrett Winters",
"Position": "Accountant",
"Address": "Tokyo",
"No": "8422"
}
]
Result I want is :
{
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422"
]
]
}
Is it possible to custom the output using Newtonsoft? I tried writing my own code to serialize the DataTable by using foreach
on the DataTable
but the performance is night and day compared to Newtonsoft.
Any help will be appreciated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…