Drill down unknown levels JSON response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robertybob
    New Member
    • Feb 2013
    • 116

    Drill down unknown levels JSON response

    Hi

    I am retrieving a JSON response for a menu (via NewtonSoft) and am successfully parsing it for use.

    The problem is that the end data I need could be 3 levels down or could be 7 levels down. How do I efficiently go about drilling down until I reach the final node?

    The main issue is that I have no way to know at what point the path will end so I cannot just drill down 5 levels each time - every single path can have different number of levels.

    So each bit of data could either be the end node or it could contain another set of nodes.

    I need an efficient way to do the following sort of thing so I can build the menu tree.

    Code:
    For Each result As myresult In jsonresp.data
        If result.hasnodes Is Nothing Then
            ' store the data and exit
        Else
            ' repeat process on all nodes on next level
        End If
    Next
    Hope that makes some sort of sense! Many thanks!
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Put a while loop inside your for loop.
    pseudo
    Code:
     For Each result As myresult In jsonresp.data
    tmp=result
    while tmp.hasnodes
     tmp=nextnode
    end while
    Next

    Comment

    • robertybob
      New Member
      • Feb 2013
      • 116

      #3
      thx clint - will give this a go

      Comment

      Working...