I am currently using the Newtonsoft framework to serialize my product categories dataset into json data.
The current way i do it is:
Public Function Category() As String
Try
Dim ds As DataSet = getDataSetFromPTLSAGE("website.CategoryList", db_conx("xxxxxxxxxxxx"))
Dim string_ As String
string_ = JsonConvert.SerializeObject(ds, Newtonsoft.Json.Formatting.Indented)
Return string_
Catch ex As Exception
Return ex.ToString
End Try
End Function
This works well and produces results like this:
{
"Table": [
{
"Id": "21",
"Name": "Accessories",
"URLFriendlyName": "accessories"
},
{
"Id": "06",
"Name": "Baby",
"URLFriendlyName": "baby"
},
{
"Id": "01",
"Name": "Bath & Shower",
"URLFriendlyName": "bath-shower"
},
{
"Id": "18",
"Name": "Books & Stationery",
"URLFriendlyName": "books-stationery"
}
]
}
Now what I would like to do is insert the sub categories into the json output. I can obtain the sub category data easily enough and put it into a dataset but what is the best method to have an array of objects inside the current object. The output should look like this:
{
"Table": [
{
"Id": "21",
"Name": "Accessories",
"URLFriendlyName": "accessories",
"SubCategory": [
{
"Id":"01",
"Name":"Travel",
"URLFriendlyName":"travel"
},
{
"Id":"02",
"Name":"Umbrella",
"URLFriendlyName":"umbrella"
}
]
}
]
}
Any thoughts and suggestions how i would serialise a linked datatable inside a dataset?