Imports System.Collections.Generic
Imports Newtonsoft.Json.Linq
" ""ID"": 43545325253," +
" ""name"": ""FY1955: PAT""," +
" ""objCode"": ""PROJ""," +
" ""parameterValues"": {" +
" ""DE:Please Enter Requested"": ""/rss55.edu""," +
" ""DE:URL Allocation 1"": ""Society Scholarship""," +
" ""DE:Is this being created for other purposes?"": ""no""," +
" ""DE:Request Submitted by"": ""urser55""," +
" ""DE:Project Owner"": ""Admin User""," +
" ""DE:App Code"": ""YDAR""," +
" ""DE:App Completion Date"": ""2018-12-14""," +
" ""University-Wide""," +
" ""DE:App 1 Long Name - 1"": ""Pref Univ""," +
" ""DE:Mailing Components"": [" +
" ""DE:App Alloc 1 Code"": ""ABBRC""" +
Dim root As RootObject = JsonConvert.DeserializeObject(Of RootObject)(json)
For Each item In root.Data
Console.WriteLine("ID: " & item.ID)
Console.WriteLine("Name: " & item.Name)
Console.WriteLine("ObjCode: " & item.ObjCode)
Console.WriteLine(String.Format("{0,-45} {1}", "Parameter Name", "Parameter Value"))
Console.WriteLine(New String("-", 45) & " " & New String("-", 45))
For Each kvp In item.ParameterValues
Console.WriteLine(String.Format("{0,-45} {1}", kvp.Key, String.Join(", ", kvp.Value)))
Public Property Data As List(Of Item)
Public Property ID As String
Public Property Name As String
Public Property ObjCode As String
<JsonConverter(GetType(SingleOrArrayDictionaryConverter(Of String)))>
Public Property ParameterValues As Dictionary(Of String, List(Of String))
Public Class SingleOrArrayDictionaryConverter(Of T)
Public Overrides Function CanConvert(objectType As Type) As Boolean
Return objectType = GetType(Dictionary(Of String, List(Of T)))
Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
Dim obj = JObject.Load(reader)
Dim dict = New Dictionary(Of String, List(Of T))
For Each prop In obj.Properties()
If prop.Value.Type = JTokenType.Array Then
dict.Add(prop.Name, prop.Value.ToObject(Of List(Of T)))
dict.Add(prop.Name, New List(Of T) From {prop.Value.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()