I have a json string as below
{
'Sheet1': [{
'EmployeeNo': '123456',
'EmployeeName': 'Midhun Mathew'
}, {
'EmployeeNo': '123457',
'EmployeeName': 'Bill Gates'
}, {
'EmployeeNo': '123456',
'Address': 'AAAA'
}, {
'EmployeeNo': '123457',
'Address': 'BBBB'
}]
}
JObject parsedJson = JObject.Parse(jsonString);
// Get the EmployeeNo's
List<JToken> tokenList = parsedJson["Sheet1"]
.GroupBy(d => d["EmployeeNo"])
.Select(s => s.Key)
.ToList();
// Get the tokens which have the Same 'EmployeeNo'
foreach (JToken j in tokenList)
{
IEnumerable<JToken> t = parsedJson["Sheet1"].Where(s => s["EmployeeNo"] == j);
}
But in the foreach I am getting only the first one which is
{
"EmployeeNo": "123456",
"EmployeeName": "Midhun Mathew"
}
I am not getting what I am doing wrong here.
My original intent is to group the JTokens having same EmployeeNo into one JObject
So in the above case I will get 2 JObjects since there are 2 different EmployeeNo's
Hope I am clear

var tokenList = parsed["Sheet1"] .OrderBy(o => o["EmployeeNo"]) .SelectMany(grp => grp.Skip(1));