So here is my JSON:
[
{
"Assignees": [
{
"ID": "1111",
"IsPrimaryOffice": true
},
{
"ID": "2222",
"IsPrimaryOffice": false
}
],
"Height": "76",
"Width": "78",
"Top": "160",
"Left": "99.5"
},
{
"Assignees": [
{
"ID": "3333",
"IsPrimaryOffice": true
},
{
"ID": "4444",
"IsPrimaryOffice": false
}
],
"Height": "11",
"Width": "11",
"Top": "11",
"Left": "11"
},
{
"Assignees": null,
"Height": "22",
"Width": "22",
"Top": "22",
"Left": "22"
},
]
Where each main object in my array holds an array of sub-objects "Assignees".
So what I'm trying to do is to search each "Assignees" object in its array for a match on ID.
For example: I want to find the Assignee object which has an ID of "3333" and also has a true value for IsPrimaryOffice with LINQ. How can I do that? Here is what I came up with, but it always returns null:
mainObject.Where(x =>
x.Assignees != null &&
x.Assignees.Any(y => y.ID == "3333" && y.IsPrimaryOffice == true))
.FirstOrDefault();
Can anyone help me out here? Thank you in advance