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 8490887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:15:23+00:00 2026-06-10T22:15:23+00:00

I have a unique issue. My program is getting bookmarks from chrome, from a

  • 0

I have a unique issue. My program is getting bookmarks from chrome, from a Bookmarks JSON file. I am using the JSON.net dll for this. My issue is, is that I need to get each URL in its correct folder hierarchy, however, it seems that you can create an infinate amount of folders to hold the bookmarks in. Here is an example of the JSON hiarchy:

{
   "checksum": "c9e24e7fb3c6cb184fb776e32dd1004e",
   "roots": {
      "bookmark_bar": {
         "children": [ {
{
"children": [ {
   "children": [ {
      "children": [ {
         "children": [ {
            "date_added": "12985566069697953",
            "id": "225",
            "name": "EvasiveURL",
            "type": "url",
            "url": "evasiveurl.com"
         } ],
         "date_added": "12991165233108137",
         "date_modified": "12991165244676611",
         "id": "374",
         "name": "NestedFolder2",
         "type": "folder"
      } ],
      "date_added": "12991165215985934",
      "date_modified": "12991165215985934",
      "id": "373",
      "name": "NestedFolder",
      "type": "folder"
   } ],
   "date_added": "12985566069695953",
   "date_modified": "12991165219618934",
   "id": "204",
   "name": "Games",
   "type": "folder"
}

And here is my current code:

for (int i = 0; o["roots"]["bookmark_bar"]["children"][i] != o["roots"]["bookmark_bar"]["children"].Last; i++)
{
    var property = o["roots"]["bookmark_bar"]["children"][i]["url"];
    var property2 = o["roots"]["bookmark_bar"]["children"][i]["children"];
    Console.WriteLine(o["roots"]["bookmark_bar"]["children"][i]["type"]);
    if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "url") {
        Console.WriteLine("URL");
    }

    else if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "folder")
    {
        Console.WriteLine("FOLDER");
        for (int ii = 0; o["roots"]["bookmark_bar"]["children"][i]["children"][ii] != o["roots"]["bookmark_bar"]["children"][i]["children"].Last; ii++)
        {
            property = o["roots"]["bookmark_bar"]["children"][i]["children"][ii];
          //  Console.WriteLine(property);
            if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "url")
            {
                Console.WriteLine("URL");
            }

            else if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "folder")
            {
                for (int iii = 0; o["roots"]["bookmark_bar"]["children"][i]["children"][ii]["children"][iii] != o["roots"]["bookmark_bar"]["children"][i]["children"][ii]["children"].Last; iii++)
                {
                    if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "url")
                    {
                        Console.WriteLine("URL");
                    }
                    else if (o["roots"]["bookmark_bar"]["children"][i]["type"].ToString() == "folder")
                    {
                        //etc. etc.
                    }
                }
            }
        }
    }
}

So, how can I rewrite this code, without copy/pasting the previous for loops and If-Else statements into where I said ‘etc. etc’?

Thanks!

Edit: This is class o:

JsonSerializer serializer = new JsonSerializer();
var o = (JToken)serializer.Deserialize(jsonReader);
  • 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-06-10T22:15:24+00:00Added an answer on June 10, 2026 at 10:15 pm

    This would be a solution for your problem. As I said you process childs recursive.

    private void processJsonInput()
    {
      var reader = new StreamReader(new FileStream("d:\\jsonfile.txt", FileMode.Open));
    
      JsonSerializer serializer = new JsonSerializer();
      var o = (JToken)serializer.Deserialize(new JsonTextReader(reader));
    
      foreach (var child in o["roots"]["bookmark_bar"]["children"])
      {
        processChild(child);
      }
    }
    
    private void processChild(JToken child)
    {
      if (child["type"].ToString() == "url")
      {
        Console.WriteLine("URL");
      } 
      else if (child["type"].ToString() == "folder")
      {
        Console.WriteLine("FOLDER");
        // process sub childrens in the folder
        foreach (var subChild in child["children"])
        {
          processChild(subChild);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this issue with Hibernate that when i try to retrieve unique result
I know that using the following codes will make each column have unique values,
Scenario: I am parsing values from an XML file using C# and have the
I have a unique issue - I am designing a web application that creates
i have got a unique issue, i had put this script on body onload
I have this issue that I want to resolve. Lets think we have this
I have an application that reads a table from a database. I issue an
I rarely use SQL and have a unique issue I need to solve. I
I have an SQL database with a set of tables that have Unique Id's.
I'm wondering if it is possible to have unique characters that cannot be seen

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.