StrugglingCoder StrugglingCoder - 21 days ago 5
C# Question

No best type found for implicitly-typed array Json error

I have an array that is separate named

scheduleList
like :

var scheduleListAll = await DataService.GetSchedule(Id);
scheduleList = scheduleListAll.ScheduleItems;


And I have another array named
doorsForSite
like :

var doorsForSite = new[]
{
new { ControllerId ="controller1",ControllerName="C1",IsChecked = "false",
Doors = new[]
{
new { DoorId="Door1",DoorName="DoorOne"},
new { DoorId = "Door2", DoorName = "DoorTwo" }
},
scheduleList

},
new { ControllerId ="controller2",ControllerName="C2",IsChecked = "false",
Doors = new[]
{
new { DoorId= "Door3",DoorName="DoorThree"},
new { DoorId = "Door4", DoorName = "DoorFour" },
new { DoorId = "Door5", DoorName = "DoorFive" },
}

}
};


How to include the
first array
into the
second
?

I tried :

var doorsForSite = new[]
{
new { ControllerId ="controller1",ControllerName="Eagle",IsChecked = "false",new object[] { scheduleList },
Doors = new[]
{
new { DoorId="Door1",DoorName="DoorOne"},
new { DoorId = "Door2", DoorName = "DoorTwo" }
},
scheduleList

},
new { ControllerId ="controller2",ControllerName="NetAxis",IsChecked = "false",new object[] { scheduleList },
Doors = new[]
{
new { DoorId= "Door3",DoorName="DoorThree"},
new { DoorId = "Door4", DoorName = "DoorFour" },
new { DoorId = "Door5", DoorName = "DoorFive" },
}

}
};


But did not work. What to do ?

Answer

You must have a key, you can't directly put array in there.

Something like

{ ControllerId ="controller1",ControllerName="Eagle",IsChecked = "false",new object[] { scheduleList },
    Doors = new[]
    {
        new { DoorId="Door1",DoorName="DoorOne"},
        new { DoorId = "Door2", DoorName = "DoorTwo" }
    },
    ScheduleList = scheduleList //like this
}