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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:10:44+00:00 2026-06-13T20:10:44+00:00

I am serializing a Multidimensional list using JSON.Net, and I am having problems making

  • 0

I am serializing a Multidimensional list using JSON.Net, and I am having problems making it serialize correctly.

Here is the result I expected from this:

     "children": [ {
        "children": [ {
           "children": [ {
              "date_added": "12995911618983970",
              "id": "8",
              "name": "NestedNestedURL",
              "type": "url",
              "url": "http://url.com/"
           } ],
           "date_added": "12995911579845538",
           "date_modified": "12995911618983970",
           "id": "5",
           "name": "NestedNestedFolder",
           "type": "folder"
        }, {
           "date_added": "12995911609609970",
           "id": "7",
           "name": "NestedURL",
           "type": "url",
           "url": "http://url.com/"
        } ],
        "date_added": "12995911570603538",
        "date_modified": "12995911609609970",
        "id": "4",
        "name": "NestedFolder",
        "type": "folder"
     }, {
        "children": [ {
           "date_added": "12995911631570970",
           "id": "9",
           "name": "NestedURL2",
           "type": "url",
           "url": "http://url.com/"
        } ],
        "date_added": "12995911589790970",
        "date_modified": "12995911631570970",
        "id": "6",
        "name": "NestedFolder2",
        "type": "folder"
     }

However, this is very different than the result I actually get. The issue here, I believe, is that multiple URL’s can belong to a single folder, and multiple folders to one folder, but I am unsure of how to implement this. Here is the code I currently use:

public void Sync()
{
    Browser browser = new Chrome();
    SortableBindingList<Bookmark> marks = browser.ReturnBookmarks();
    SortableBindingList<object> newmarks = new SortableBindingList<object>();
    int count = 0;
   newmarks.Add(new json_top());
    json_top top = newmarks[0] as json_top;

    top.roots = new json_root();
    List<object> roots = new List<object>();

    Folder bookmarks_bar = new Folder();
    Folder other = new Folder();
    List<Object> barlist = new List<Object>();
    List<object> otherlist = new List<object>();
    List<object> children = new List<object>();
    List<string> existingFolders = new List<string>();

    bookmarks_bar.date_added = ToChromeTime(marks[0].added);
    bookmarks_bar.name = "Bookmarks bar";
    other.date_added = ToChromeTime(marks[0].added);
    other.name = "Other bookmarks";

    bool isBookmarkBar = true;

    Folder folder = new Folder();
    foreach (Bookmark mark in ordered)
    {
        List<string> fullpathlist = mark.fullPath.Split('\\').ToList();
        int count1 = 0;
        if (currentPath != mark.fullPath)
        {
            folder = (createFolder(fullpathlist, fullpathlist[0], mark));
            folder.children.Add(setChild(fullpathlist, folder, mark, 1));
            count++;
        }
        json_URL u = new json_URL();
        u.date_added = ToChromeTime(mark.added);
        u.id = id;
        u.name = mark.title;
        u.url = mark.url;
        folder.children.Add(u);
        if(isBookmarkBar)
            barlist.Add(folder);
        else
        {
            otherlist.Add(folder);
        }
    }
    bookmarks_bar.children = barlist;
    other.children = otherlist;
    top.roots.bookmark_bar = (bookmarks_bar);
    top.roots.other = other;
    string json = JsonConvert.SerializeObject(newmarks, Formatting.Indented);
    File.WriteAllText(@"c:\person.json", json);
}

    Folder setChild(List<string> fullPathList, Folder parent, Bookmark mark, int count )
    {
        if (count < fullPathList.Count)
        {
            Folder child = new Folder();
            child.date_added = ToChromeTime(mark.added);
            child.id = id;
            child.name = fullPathList[count];
            Folder LIST = setChild(fullPathList, child, mark, count + 1);
            child.children= LIST;
            return child;
        }            
    }

    public class Folder
    {
        public List<folderAndURL> children { get; set; }
        public long date_added { get; set; }
        public long date_modified
        {
            get { return 0; }
        }
        public int id { get; set; }
        public string name { get; set; }
        public string type
        {
            get { return "folder"; }
        }
    }

And here is the output I get from that code:

    "children": [
      {
        "children": {
          "date_added": 12995893609609970,
          "id": 0,
          "name": "NestedURL",
          "type": "url",
          "url": "http://url.com/"
        },
        "date_added": 12995893609609970,
        "date_modified": 0,
        "id": 0,
        "name": "NestedFolder",
        "type": "folder"
      },
      {
        "children": {
          "date_added": 12995893618983970,
          "id": 1,
          "name": "NestedNestedURL",
          "type": "url",
          "url": "http://url.com/"
        },
        "date_added": 12995893618983970,
        "date_modified": 0,
        "id": 1,
        "name": "NestedFolder",
        "type": "folder"
      },
      {
        "children": {
          "date_added": 12995893631570970,
          "id": 2,
          "name": "NestedURL2",
          "type": "url",
          "url": "http://url.com/"
        },
        "date_added": 12995893631570970,
        "date_modified": 0,
        "id": 2,
        "name": "NestedFolder2",
        "type": "folder"
      }

So, how can I change my code to match the input and the output? Like I said, it seems to be something about multiple folders not being applied to one parent folder.

Edit: I have uploaded a full version of the code here, because I cut out some parts due to space.

  • 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-13T20:10:45+00:00Added an answer on June 13, 2026 at 8:10 pm

    I don’t know if this is what you want:

    /// <summary>
    /// Load file from
    /// C:\Users\XXXX\AppData\Local\Google\Chrome\User Data\Default\Bookmarks
    /// </summary>
    [TestFixture]
    public class ChromeBookmarks
    {
        [Test]
        public void RoundTripBookmarksTest()
        {
            JsonSerializer jsonSerializer = JsonSerializer.Create(
                new JsonSerializerSettings
                    {
                        MissingMemberHandling = MissingMemberHandling.Error,
                    });
            RootObject rootObject;
            using (JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(Properties.Resources.Bookmarks))) //I added my bookmars as an embedded txt file for convenience
            {
                rootObject = jsonSerializer.Deserialize<RootObject>(jsonTextReader);
            }
            //Here you have the contents of the bookmarks file in rootObject if you need to do manipulations
            StringBuilder stringBuilder = new StringBuilder();
            using (JsonTextWriter jsonTextWriter = new JsonTextWriter(new StringWriter(stringBuilder)))
            {
                jsonTextWriter.Formatting = Formatting.Indented;
                jsonTextWriter.Indentation = 3;
                jsonSerializer.Serialize(jsonTextWriter, rootObject);
            }
            var json = stringBuilder.ToString();
            File.WriteAllText(@"C:\person.json", json);
        }
    }
    
    public class Child
    {
        [JsonProperty(PropertyName = "children")]
        public List<Child> Children { get; set; }
        [JsonProperty(PropertyName = "date_added")]
        public string DateAdded { get; set; }
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }
        [JsonProperty(PropertyName = "name")]
        public string Name { get; set; }
        [JsonProperty(PropertyName = "type")]
        public string Type { get; set; }
        [JsonProperty(PropertyName = "url")]
        public string Url { get; set; }
        [JsonProperty(PropertyName = "date_modified")]
        public string DateModified { get; set; }
    }
    
    public class Roots
    {
        [JsonProperty(PropertyName = "bookmark_bar")]
        public Child BookmarkBar { get; set; }
        [JsonProperty(PropertyName = "other")]
        public Child Other { get; set; }
        [JsonProperty(PropertyName = "synced")]
        public Child Synced { get; set; }
    }
    
    public class RootObject
    {
        [JsonProperty(PropertyName = "checksum")]
        public string Checksum { get; set; }
        [JsonProperty(PropertyName = "roots")]
        public Roots Roots { get; set; }
        [JsonProperty(PropertyName = "version")]
        public int Version { get; set; }
    }
    

    I used this to generate the classes, did not read the docs just passed my bookmarks so there is a chance some field is missing.

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

Sidebar

Related Questions

I am having problems serializing a cdata section using c# I need to serialize
I'm serializing data from my Django model into json and placing that info in
Possible Duplicate: Serializing to JSON in jQuery I'm using jquery as a library in
When serializing an object using the System.Runtime.Serialization.Json.DataContractJsonSerializer , is there a way to set
I have been happy serializing with javascript objects into JSON using JSON.stringify And sending
I'm serializing a bunch of objects with: json = serializers.serialize(json, objects, fields=('name', 'country')) I
Possible Duplicate: Serializing to JSON in jQuery I know how to serialize an object
I'm serializing a list of ObservableCollection<MyType> using this line of code and it works
I am having trouble serializing an ArrayList into an XML in .NET. I am
I am serializing a class using simple-xml ( http://simple.sourceforge.net/ ) but when i try

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.