-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewJSON.vb
More file actions
61 lines (49 loc) · 2.23 KB
/
ViewJSON.vb
File metadata and controls
61 lines (49 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Imports System.Text
Imports Microsoft.VisualBasic.ComponentModel
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports Microsoft.VisualBasic.MIME.application.json
Imports Microsoft.VisualBasic.MIME.application.json.Javascript
Imports Microsoft.VisualBasic.Net.Protocols.ContentTypes
Imports Microsoft.VisualBasic.Text
Imports WeifenLuo.WinFormsUI.Docking
Public Class ViewJSON : Implements Viewer
Public Property FilePath As String Implements IFileReference.FilePath
Public ReadOnly Property MimeType As ContentType() Implements IFileReference.MimeType
Get
Throw New NotImplementedException()
End Get
End Property
Public Function View(file As String) As DockContent Implements Viewer.View
Dim json As JsonElement = file.ReadAllText.ParseJson
Dim root As New TreeNode With {.Text = file.FileName}
TabText = file.FileName
TreeView1.Nodes.Add(root)
loadJson(json, root)
FilePath = file
Return Me
End Function
Private Sub loadJson(json As JsonElement, tree As TreeNode)
If TypeOf json Is JsonArray Then
Dim array As TreeNode = tree.Nodes.Add("[]")
For Each item In DirectCast(json, JsonArray)
Call loadJson(item, array)
Next
ElseIf TypeOf json Is JsonObject Then
Dim obj As TreeNode = tree.Nodes.Add("{}")
For Each item As NamedValue(Of JsonElement) In DirectCast(json, JsonObject)
loadJson(item.Value, obj.Nodes.Add(item.Name))
Next
ElseIf TypeOf json Is JsonValue Then
tree.Nodes.Add(DirectCast(json, JsonValue).GetStripString(decodeMetachar:=True))
End If
End Sub
Public Function Save(path As String, encoding As Encoding) As Boolean Implements ISaveHandle.Save
Throw New NotImplementedException()
End Function
Public Function Save(path As String, Optional encoding As Encodings = Encodings.UTF8) As Boolean Implements ISaveHandle.Save
Throw New NotImplementedException()
End Function
Public Function Save(file As IO.Stream, encoding As Encoding) As Boolean Implements ISaveHandle.Save
Throw New NotImplementedException()
End Function
End Class