C# – Convert Newtonsoft.Json.Linq.JArray to a list of specific object type

cjson.net

I have the following variable of type {Newtonsoft.Json.Linq.JArray}.

properties["Value"] {[
  {
    "Name": "Username",
    "Selected": true
  },
  {
    "Name": "Password",
    "Selected": true
  }

]}

What I want to accomplish is to convert this to List<SelectableEnumItem> where SelectableEnumItem is the following type:

public class SelectableEnumItem
    {
        public string Name { get; set; }
        public bool Selected { get; set; }
    }

I am rather new to programming and I am not sure whether this is possible. Any help with working example will be greatly appreciated.

Best Answer

Just call array.ToObject<List<SelectableEnumItem>>() method. It will return what you need.

Documentation: Convert JSON to a Type