If I have a datatable in the following structure.
HostelName FloorName FlatName Occupied Vacant Building One Floor A A 2 2 Building One Floor A B 0 4 Building One Floor A C 0 4 Building One Floor A D 0 4 Building One Floor A E 0 4 Building One Floor B F 0 4 Building One Floor B G 0 4 Building One Floor B H 0 4 Building One Floor B I 0 4 Building One Floor B J 0 4
I would like to serialize it as a JSON object where the HostelName,FloorName & FlatName columns are the nodes in the JSON object like:
{
"Building One": {
"Floor A": {
"A": {
"Occupied": "2",
"Vacant": "2"
},
"B": {
"Occupied": "0",
"Vacant": "4"
},
"C": {
"Occupied": "0",
"Vacant": "4"
},
"D": {
"Occupied": "0",
"Vacant": "4"
},
"E": {
"Occupied": "0",
"Vacant": "4"
}
},
"Floor B": {
"F": {
"Occupied": "0",
"Vacant": "4"
},
"G": {
"Occupied": "0",
"Vacant": "4"
},
"H": {
"Occupied": "0",
"Vacant": "4"
},
"D": {
"Occupied": "0",
"Vacant": "4"
},
"I": {
"Occupied": "0",
"Vacant": "4"
}
}
}
};
Please help me to solve it.
All you have to do is using a custom JSONConverter (in case of useing JSON.NET), learn about that here (JSON.NET Implementing Custom Serialization).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With