Imports System.Collections
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Reflection
Imports System.ComponentModel.DataAnnotations
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json.Converters
Imports Newtonsoft.Json.Serialization
Public Property Email As String
Public Property Timestamp As String
Public Property Number As Long
Public Module JsonExtensions
Public Function LoadAnonymousType(Of T)(ByVal path as String, ByVal anonymousTypeObject as T, Optional ByVal settings as JsonSerializerSettings = Nothing) as T
Using streamReader As TextReader = File.OpenText(path)
Dim serializer = JsonSerializer.CreateDefault(settings)
return CType(serializer.Deserialize(streamreader, GetType(T)), T)
Dim FileName As String = "Question56315777.json"
File.WriteAllText(FileName, GetJson())
Friend Sub TestAnonymous(FileName as String)
Console.WriteLine("Deserializing an array of anonymous objects:")
Dim array = JsonExtensions.LoadAnonymousType( _
{ New With {.Email = CType(Nothing, String), .Timestamp = CType(Nothing, String), .Number = CType(Nothing, Long) }} _
Console.WriteLine("Email = {0}, Timestamp = {1}, Number = {2}", item.Email, item.Timestamp, item.Number)
Friend Sub TestExplicit(FileName as String)
Console.WriteLine("Deserializing a list of RootObjects:")
Dim list As List(Of RootObject) = Nothing
Using streamReader As TextReader = File.OpenText(FileName)
list = CType(JsonSerializer.CreateDefault().Deserialize(streamReader, GetType(List(Of RootObject))), List(Of RootObject))
Console.WriteLine("Email = {0}, Timestamp = {1}, Number = {2}", item.Email, item.Timestamp, item.Number)
Function GetJson() as String
Dim Jstring As String = <![CDATA[
"Timestamp": "2019-05-25T21:24:06.799381+02:00",
"randomtrash1": "notneeded",
"randomtrash2": "notneeded",
"randomtrash3": "notneeded",
"randomtrash4": "notneeded",
"randomtrash5": "notneeded",
"randomtrash6": "notneeded",
"randomtrash7": "notneeded",
"randomtrash8": "notneeded",
"randomtrash9": "notneeded"
"Timestamp": "2019-05-25T21:24:06.8273826+02:00",
"randomtrash1": "notneeded",
"randomtrash2": "notneeded",
"randomtrash3": "notneeded",
"randomtrash4": "notneeded",
"randomtrash5": "notneeded",
"randomtrash6": "notneeded",
"randomtrash7": "notneeded",
"randomtrash8": "notneeded",
"randomtrash9": "notneeded",
"randomtrash10": "notneeded",
"randomtrash11": "notneeded",
"randomtrash12": "notneeded",
"randomtrash13": "notneeded",
"randomtrash14": "notneeded",
"randomtrash15": "notneeded",
"randomtrash16": "notneeded",
"randomtrash17": "notneeded",
"randomtrash18": "notneeded",
"randomtrash19": "notneeded",
"randomtrash20": "notneeded",
"randomtrash21": "notneeded"
Console.WriteLine("Environment version: " & Environment.Version.ToString())
Console.WriteLine("Json.NET version: " & GetType(JsonSerializer).Assembly.FullName)
Console.WriteLine("Unhandled exception: ")