Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
Dim jsonstr as string = "{" guid ":" root________ "," title ":""," index ":0," dateAdded ":1578289286361000," lastModified ":1590117014008000," id ":1," typeCode ":2," type ":" text / x - moz - place - container "," root ":" placesRoot ","c hildren ":[{" guid ":" menu________ "," title ":" menu "," index ":0," dateAdded ":1578289286361000," lastModified ":1586933219617000," id ":2," typeCode ":2," type ":" text / x - moz - place - container "," root ":" bookmarksMenuFolder "},{" guid ":" toolbar_____ "," title ":" toolbar "," index ":1," dateAdded ":1578289286361000," lastModified ":1590117014008000," id ":3," typeCode ":2," type ":" text / x - moz - place - container "," root ":" toolbarFolder ","c hildren ":[{" guid ":" vxl05Fwl0IM6 "," title ":" 開課資訊 – 亥客書院 "," index ":0," dateAdded ":1575855573000000," lastModified ":1590117012092000," id ":20811," typeCode ":1," type ":" text / x - moz - place "," uri ":" https : / / hackercollege.nctu.edu.tw /? page_id = 44 "}]},{" guid ":" unfiled_____ "," title ":" unfiled "," index ":3," dateAdded ":1578289286361000," lastModified ":1578988830554000," id ":5," typeCode ":2," type ":" text / x - moz - place - container "," root ":" unfiledBookmarksFolder "},{" guid ":" mobile______ "," title ":" mobile "," index ":4," dateAdded ":1578289286548000," lastModified ":1578289290180000," id ":6," typeCode ":2," type ":" text / x - moz - place - container "," root ":" mobileFolder "}]}" 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