I want to grab each jarray json for each unique stopnumber, that was last inserted.
For example:
[StopNumber = 1, Inserted 11-17],
[StopNumber = 2, Inserted 11-17],
[StopNumber = 1, Inserted 11-11]
The Jarray I would want returned is
[StopNumber = 1, Inserted 11-17],
[StopNumber = 2, Inserted 11-17]
This is the code I have that doesn’t work:
new JArray(
R_Content_Fixed
.Where(doc =>
{
var stopNoField = doc["Fields"].FirstOrDefault(field => field["Name"].Value<string>() == "STOPNO");
return stopNoField != null && !string.IsNullOrEmpty(stopNoField["Value"].Value<string>());
})
.GroupBy(doc => doc["Fields"].First(field => field["Name"].Value<string>() == "STOPNO")["Value"].Value<string>())
.Select(group => group.OrderByDescending(doc => doc["InsertDateTime"].Value<DateTime>()).First())
)
Part of my Jarray:
[
{
“Bytes”: “”,
“DocumentId”: “RTMS20-B800015740-1”,
“DocClassName”: “RTMS20”,
“InsertDateTime”: “2023-10-11T09:43:22”,
“ImportDateTime”: “2023-10-11T09:43:22”,
“FileType”: “PDF”,
“Annotations”: ,
“Fields”: [
{
“Name”: “ORDERNO”,
“Value”: “12141902”
},
{
“Name”: “BILLTOID”,
“Value”: “12141902”
},
{
“Name”: “BOLNO”,
“Value”: “”
},
{
“Name”: “DOCTYPE”,
“Value”: “EBOL”
},
{
“Name”: “INVNO”,
“Value”: “”
},
{
“Name”: “BATCHID”,
“Value”: “12141902_61164208_5”
},
{
“Name”: “TERMINAL”,
“Value”: “N/A”
},
{
“Name”: “STOPNO”,
“Value”: “61164208”
},
{
“Name”: “REFNUM”,
“Value”: “12141902”
}
]
},
{
“Bytes”: “1”,
“DocumentId”: “RTMS20-B800015760-1”,
“DocClassName”: “RTMS20”,
“InsertDateTime”: “2023-10-11T10:06:34”,
“ImportDateTime”: “2023-10-11T10:06:34”,
“FileType”: “PDF”,
“Annotations”: ,
“Fields”: [
{
“Name”: “ORDERNO”,
“Value”: “12141902”
},
{
“Name”: “BILLTOID”,
“Value”: “12141902”
},
{
“Name”: “BOLNO”,
“Value”: “”
},
{
“Name”: “DOCTYPE”,
“Value”: “EBOL”
},
{
“Name”: “INVNO”,
“Value”: “”
},
{
“Name”: “BATCHID”,
“Value”: “12141902_61164208_6”
},
{
“Name”: “TERMINAL”,
“Value”: “N/A”
},
{
“Name”: “STOPNO”,
“Value”: “61164208”
},
{
“Name”: “REFNUM”,
“Value”: “12141903”
}
]
},
{
“Bytes”: “3”,
“DocumentId”: “RTMS20-B800015780-1”,
“DocClassName”: “RTMS20”,
“InsertDateTime”: “2023-10-17T13:26:21”,
“ImportDateTime”: “2023-10-17T13:26:21”,
“FileType”: “PDF”,
“Annotations”: ,
“Fields”: [
{
“Name”: “ORDERNO”,
“Value”: “12141902”
},
{
“Name”: “BILLTOID”,
“Value”: “12141902”
},
{
“Name”: “BOLNO”,
“Value”: “”
},
{
“Name”: “DOCTYPE”,
“Value”: “EBOL”
},
{
“Name”: “INVNO”,
“Value”: “”
},
{
“Name”: “BATCHID”,
“Value”: “12141902_61164208_13”
},
{
“Name”: “TERMINAL”,
“Value”: “”
},
{
“Name”: “STOPNO”,
“Value”: “61164210”
},
{
“Name”: “REFNUM”,
“Value”: “12141902”
}
]
}}