Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim dtTICKET As New DataTable
dtTICKET.Columns.Add("Title", GetType(String))
dtTICKET.Columns.Add("Queue", GetType(String))
dtTICKET.Rows.Add("New Updates", "Updates")
'dtTICKET.Rows.Add("Lost connection", "Network")
Dim dtJSON As New DataTable
dtJSON.Columns.Add("UserLogin", GetType(String))
dtJSON.Columns.Add("Password", GetType(String))
dtJSON.Columns.Add("Ticket", GetType(DataTable))
dtJSON.Rows.Add("[email protected]", "pwd", dtTICKET)
json = JToken.FromObject(dtJSON).ToString()
End Sub
executing this code results in
[
{
"UserLogin": "[email protected]",
"Password": "pwd",
"Ticket": [
{
"Title": "New Updates",
"Queue": "Updates"
}
]
}
]
but I need curly brackets instead of square brackets for the child “Ticket” if dtTicket only has one row
I tried to use a custom JsonSerializer and set IndentChar for Formatting. But I don’t know if that is the right way and how to do this
Does anyone know how to fix this ?
AndreasA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
I created a plain object for dtJson and dtTicket because my REST API needs a single ticket and by that it works
Public Class Ticket
Public Title As String
Public QueueID As String
Public TypeID As String
Public State As String
Public Priority As String
Public CustomerUser As String
Public Article As DataTable
End Class
Public Class Json
Public UserLogin As String
Public Password As String
Public Ticket As Ticket
End Class
AndreasA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1