By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,061 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,061 IT Pros & Developers. It's quick & easy.

Drill down unknown levels JSON response

100+
P: 116
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.

Expand|Select|Wrap|Line Numbers
  1. For Each result As myresult In jsonresp.data
  2.     If result.hasnodes Is Nothing Then
  3.         ' store the data and exit
  4.     Else
  5.         ' repeat process on all nodes on next level
  6.     End If
  7. Next
  8.  
Hope that makes some sort of sense! Many thanks!
Oct 11 '14 #1

✓ answered by iam_clint

Put a while loop inside your for loop.
pseudo
Expand|Select|Wrap|Line Numbers
  1.  For Each result As myresult In jsonresp.data
  2. tmp=result
  3. while tmp.hasnodes
  4.  tmp=nextnode
  5. end while
  6. Next
  7.  
  8.  

Share this Question
Share on Google+
2 Replies


iam_clint
Expert 100+
P: 1,208
Put a while loop inside your for loop.
pseudo
Expand|Select|Wrap|Line Numbers
  1.  For Each result As myresult In jsonresp.data
  2. tmp=result
  3. while tmp.hasnodes
  4.  tmp=nextnode
  5. end while
  6. Next
  7.  
  8.  
Oct 12 '14 #2

100+
P: 116
thx clint - will give this a go
Oct 13 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.