Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4116900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:46:04+00:00 2026-05-20T22:46:04+00:00

I thought this was going to be easy, but it’s turning into quite a

  • 0

I thought this was going to be easy, but it’s turning into quite a headache. I have a multidimensional JSON object being returned from my webserver. I’m parsing it to build a fairly deep navigation pane. I need to be able to search this object, but I’m coming up blank for the means.

The object is structured as so: tree->rows[]=>tree->rows[]=>tree …

Each tree can have many rows, and each row can have a tree etc.

At the row level there are a few variables, I need to search and find the value of one.
EX: if(tree.rows[x].tree.rows[y].url =="http://stackoverflow.com" return true;

My difficulty is, I don’t know how to traverse the whole object. Even if I do it recursively I don’t know how I could keep going up and down all the rows.

Here’s an example of the object:

var jsonLNav = {itemClassName:"NodeLink",linkClassName:"NodeLinkTitle",linkHideClassName:"HideFromProd",navCategoryClassName:"NavCategory",onLoadJS:"",tree:[{pos:1,wid:"263a97c2-7cb9-470c-bf86-cadc28ae1323",pid:"1",rows:[{hide:0,title:"More IT Help",isNC:0,isMig:0,url:"http://vm-hsspdv-d09p/en-us/Help/Pages/ITHelp.aspx",isOL:0,tree:{pos:2,wid:"263a97c2-7cb9-470c-bf86-cadc28ae1323",pid:"3"}},{hide:0,title:"Office 2010",isNC:0,isMig:1,url:"http://office2010.lmig.com/Pages/Default.aspx",isOL:0,tree:{pos:2,wid:"263a97c2-7cb9-470c-bf86-cadc28ae1323",pid:"9"}},{hide:0,title:"E-mail Management",isNC:0,isMig:0,url:"http://vm-hsspdv-d09p/en-us/Help/EmailManagement/Pages/default.aspx",isOL:0,tree:{pos:2,wid:"8be66348-8da1-4e5c-90c5-0930d2f52d1a",pid:"123"}},]}]}; 

This example piece doesn’t have any child trees of the row, the object that does is tens of thousands characters long, I can post if necessary.

The best code I can think of would be close to this (not tested, conceptually I’m missing something):

function findURL(url)
{

alert(searchJson(jsonLNav.tree[0],url));
}//end findURL

function searchJson(tree,url)
{

for(var x=0; x<=tree.rows.length-1;x++)
{
    if(url == tree.rows[x].url)
    {
        return tree.rows[x].title;
    }//end if
    else
    {
        searchJson( tree.rows[x].tree,url)
    }//end else
}//end for


}//end searchJson

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:46:05+00:00Added an answer on May 20, 2026 at 10:46 pm

    When your search function calls itself recursively, it has to pay attention to the returned value, and somehow determine whether it’s found it or not. Your function doesn’t do anything special when it finds nothing, which I suppose is OK because the return value will be undefined.

    else
    {
        var t = searchJson( tree.rows[x].tree,url);
        if (t) return t;
    }//end else
    

    That way, the first loop that finds the url will return the (hopefully non-empty) “title”, and that will propagate up the stack as a non-empty value for all the “if (t)” statements on the call stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be pretty easy but I'm running into all sorts of
Initially I thought this was going to work, but now I understand it won't
I thought this would be fairly easy, but I'm totally baffled. I want one
i thought that this was going to be an easy move as what i'm
Im new on this project and am going to write, what i thought was
I am going crazy now. Googled this, thought some kind of IDE bug. Maybe
Ok, this has been an on-going annoyance, so naturally I thought to bring it
I thought this would be fairly simple but it turns out not to work
I thought this was covered elsewhere but I don't see it now. Anyway, having
I thought this would be very easy. I downloaded the JDK, extracted src.zip, modified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.