Imports Newtonsoft.Json.Linq
Console.WriteLine("---- format #1 ----")
" ""type"": ""myType""," + _
" ""action"": ""myAction""," + _
" ""method"": ""myMethod""," + _
" ""success"": true," + _
" ""nome"": ""PRIMEIRO NOME""," + _
" ""nome"": ""SEGUNDO NOME""," + _
" ""nome"": ""TERCEIRO NOME""," + _
" ""nome"": ""QUARTO NOME""," + _
Console.WriteLine("---- format #2 ----")
" ""type"": ""myType""," + _
" ""action"": ""myAction""," + _
" ""method"": ""myMethod""," + _
" ""nome"": ""PRIMEIRO NOME""," + _
" ""nome"": ""SEGUNDO NOME""," + _
" ""nome"": ""TERCEIRO NOME""," + _
" ""nome"": ""QUARTO NOME""," + _
Public Sub DeserializeAndDump(json As String)
Dim response As Response = JsonConvert.DeserializeObject(Of Response)(json)
Console.WriteLine("type: " & response.type)
Console.WriteLine("tid: " & response.tid)
Console.WriteLine("action: " & response.action)
Console.WriteLine("method: " & response.method)
Console.WriteLine("result.success: " & response.result.success)
Console.WriteLine("result.total: " & response.result.total)
Console.WriteLine("result.records: ")
For Each record As Record In response.result.records
Console.WriteLine(" id: " & record.id)
Console.WriteLine(" nome: " & record.nome)
Console.WriteLine(" sigla: " & record.sigla)
Public Property id As Integer
Public Property nome As String
Public Property sigla As String
Public Property success As Boolean
Public Property total As Integer
Public Property records As Record()
Public Property type As String
Public Property tid As Integer
Public Property action As String
Public Property method As String
<JsonConverter(GetType(ResultConverter))>
Public Property result As Result
Public Class ResultConverter
Public Overrides Function CanConvert(objectType As Type) As Boolean
Return objectType = GetType(Result)
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)
Dim result As Result = New Result
If token.Type = JTokenType.Array Then
result.records = token.ToObject(Of Record())(serializer)
result.total = result.records.Length
serializer.Populate(token.CreateReader(), result)
Public Overrides ReadOnly Property CanWrite As Boolean
Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
Throw New NotImplementedException