0

I wan't to get all subnodes in a JSON file using JSON.NET is it possible ?

Here is my code :

    Shared Function LoadBranch(ByVal branch As String, ByVal tv As TreeView)
        Dim jsonstr As String = FileIO.FileSystem.ReadAllText(FileIO.FileSystem.ReadAllText(".\temp\localpath.txt"))
        Dim obj As JObject = JObject.Parse(jsonstr)
        Dim result As List(Of JToken) = obj.Children().ToList()
        For Each item As JProperty In result
            Dim rootName As String = item.Name
            If branch = rootName Then
                Dim root As TreeNode = tv.Nodes.Add(rootName)
                For Each child In item.Children()
                    For Each jprop As JProperty In child
                        root.Nodes.Add(String.Format("{0} : {1}", jprop.Name, jprop.Value))

                    Next
                Next
            End If
        Next
        Return True
    End Function
  • 2
    Does [How to recursively populate a TreeView with JSON data](https://stackoverflow.com/questions/39673815/how-to-recursively-populate-a-treeview-with-json-data) help? It's in C#, but it is a useful skill to be able to translate C# to VB.NET - there are online translators available, although you have to become familiar with their quirks. – Andrew Morton Jun 16 '20 at 11:24
  • Also, traversing a tree (or graph) is something you should learn how to do. If you need to do it once, you'll probably need to do it again in the future. Consider the distinction of whether you want to do it depth-first (recursing into each child as you find it) or breadth first (iterating over all siblings at a level before recursing into the children). – Craig Jun 16 '20 at 13:25

0 Answers0