Код: Выделить всё
public class ObjectList : IEnumerable where T : class
{
public ObjectList()
{
this.Items = new List();
}
public string Group { get; set; }
public int Count { get => this.Items.Count; set { } }
public List Items { get; set; }
public IEnumerator GetEnumerator() { return this.Items.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return this.Items.GetEnumerator(); }
}
public class ItemList : ObjectList
{
}
Код: Выделить всё
var list = new ItemList()
{
Group = "Group",
Items = new List()
{
new ListItem() { Name = "Foo"},
new ListItem() { Name = "Bar"},
}
};
Код: Выделить всё
var txt = System.Text.Json.JsonSerializer.Serialize(list, new JsonSerializerOptions()
{
WriteIndented = true,
});
Console.WriteLine(txt);
Код: Выделить всё
[{"Name":"Foo"},{"Name":"Bar"}]
Код: Выделить всё
{"Group":"Group","Count":2,"Items":[{"Name":"Foo"},{"Name":"Bar"}]}
Можете ли вы мне помочь в этом вопросе?
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -text-json