GettingStarted
GettingStarted

Reputation: 7605

How do I make a List of Lists?

Part of my class file

namespace Calendar
{
    class CalendarModel
    {
        [JsonProperty("name")]
        public string name { get; set; }

In my implementation file, I declared a private variable

private List<CalendarModel> people;

In a method, I am getting my JSON Object with this code

people = JsonConvert.DeserializeObject<List<CalendarModel>>((string)fileContainingJSONObject);

How would I create an Array of people? Then how would I access its members (later)?

Upvotes: 0

Views: 128

Answers (1)

Josh Part
Josh Part

Reputation: 2164

Just declare a list of list of CalendarModel

var crowd = new private List<List<CalendarModel>>();

...

people = JsonConvert.DeserializeObject<List<CalendarModel>>((string)fileContainingJSONObject);
crowd.add(people)

To access the properties of the CalendarModel objects:

crowd[peopleIndex][calendarModelIndex].name

Upvotes: 2

Related Questions