I have the following variable of type {Newtonsoft.Json.Linq.JArray}. 我有这么一组数组对象
properties[
"Value"] {[
{
"Name":
"Username",
"Selected":
true
},
{
"Name":
"Password",
"Selected":
true
}
]}
现在我想转成这样的类型:List<T> ,其中T为SelectableEnumItem
public class SelectableEnumItem
{
public string Name {
get;
set; }
public bool Selected {
get;
set; }
}
如何写才正确? 如此即可,就能将此json对象转换成自己想要的类型:
array.ToObject<
List<SelectableEnumItem>>()
Documentation: Convert JSON to a Type(https://www.newtonsoft.com/json/help/html/ToObjectType.htm)
原文:https://stackoverflow.com/questions/13565245/convert-newtonsoft-json-linq-jarray-to-a-list-of-specific-object-type