Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
Dim json As String = "[{""ID"":1,""Officer"":""John Doe"",""Type"":""Moving Violation"",""Amount"":[{""Account"":100,""Price"":342},{""Account"":200,""Price"":60},{""Acctount"":300,""Price"":10}]},{""ID"":2,""Officer"":""Jane Doe"",""Type"":""Non-moving Violation"",""Amount"":[{""Account"":700,""Price"":155},{""Account"":300,""Price"":20},{""Account"":200,""Price"":120},{""Account"":500,""Price"":50}]}]"
Console.WriteLine("--- Array ---")
Sub DeserializeJSON(json As String)
Dim jTicketList As New List(Of jTicket)
Dim tickets = JArray.Parse(json)
For Each token As JToken In tickets.Children
Dim jt As jTicket = JsonConvert.DeserializeObject(Of jTicket)(token.ToString())
For Each t As jTicket In jTicketList
Console.WriteLine("ID=" + t.id.ToString())
Console.WriteLine("Type=" + t.type)
Console.WriteLine("Officer=" + t.officer)
For Each a As jTicketAmount In t.amount
Console.WriteLine("Account=" + a.account.ToString())
Console.WriteLine("Price=" + a.price.ToString())
<JsonConverter(GetType(SingleOrArrayConverter(Of jTicketAmount)))>
Public Property amount As List(Of jTicketAmount)
Public Property id As Integer
Public Property type As String
Public Property officer As String
Public NotInheritable Class jTicketAmount
Public Property account As Integer
Public Property price As Decimal
Public Class SingleOrArrayConverter(Of T)
Public Overrides Function CanConvert(objectType As Type) As Boolean
Return objectType = GetType(List(Of T))
Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
Dim token As JToken = JToken.Load(reader)
If (token.Type = JTokenType.Array) Then
Return token.ToObject(Of List(Of T))()
Return New List(Of T) From {token.ToObject(Of T)()}
Public Overrides ReadOnly Property CanWrite As Boolean
Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
Throw New NotImplementedException