Imports System.IO Imports System.Text Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Public JsonDataTable As New DataTable Private Sub AppLoad(sender As Object, e As EventArgs) Handles Me.Load Call LoadJson(Application.StartupPath & "\test.json") End Sub Private Sub LoadJson(ByVal FilePath As String) Dim enc As Encoding = Encoding.UTF8 Dim jsonStr As String 'ファイルからJson文字列を読み込む Using sr As New StreamReader(FilePath, enc) jsonStr = sr.ReadToEnd() End Using 'Json文字列をJson形式データに復元する Dim jsonObj As Object = JsonConvert.DeserializeObject(jsonStr) 'listからgrouplist内の要素を取得 Dim GrouplistArray As JArray = CType(jsonObj("list")("grouplist"), JArray) 'listのgrouplist内の要素を全て取得 For i As Integer = 0 To GrouplistArray.Count - 1 'グループの列を作成 Dim CurrentGroupName As String = GrouplistArray(i).ToString JsonDataTable.Columns.Add(CurrentGroupName) 'グループの要素を配列に格納 Dim GroupItemArray As JArray = CType(jsonObj("list")(CurrentGroupName), JArray) 'グループの配列要素をDataTableに格納 For Each Item As String In GroupItemArray Dim row As DataRow = JsonDataTable.NewRow row(CurrentGroupName) = Item JsonDataTable.Rows.Add(row) Next Next 'DataTableの内容をDataGridViewに表示 DataGridView1.DataSource = JsonDataTable End Sub