简体   繁体   中英

What is the best way of getting a json object tree from a parent child relation

Say I have a list of parent-child related folders. How can I get the following specific json object to be used by angular mat tree:

Note: the list for this will indicate Groceries and reminders are root, fruits is subfolder to groceries.

Use https://www.newtonsoft.com/json to serialize any C# Object to JSON

Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };

string json = JsonConvert.SerializeObject(product);
// {
//   "Name": "Apple",
//   "Expiry": "2008-12-28T00:00:00",
//   "Sizes": [
//     "Small"
//   ]
// }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM