我希望得到10条最新的(orderbydescenting datetime)记录,这些记录应该是唯一的,并且不应为null(ACnrAAAAAAAAAAA =)值。
示例数据
AGMDAQo1/wSsCPU=
AGjtAAAAAAAAAAA=(this should be discarded as treating null values)
AGMDAQo1/wSsCPU=
ACnrAAAAAAAAAAA=(this should be discarded as treating null values)
AWa2AQo2CQSsCNE=
json数据
[{"timestamp":"2017-03-20T05:27:01.688Z","dataFrame":"ACnrAAAAAAAAAAA=","fcnt":165,"port":3,"rssi":-85,"snr":7,"sf_used":12,"id":1489987621688,"decrypted":true},{"timestamp":"2017-03-20T05:27:41.675Z","dataFrame":"ACntAAAAAAAAAAA=","fcnt":169,"port":3,"rssi":-85,"snr":9,"sf_used":12,"id":1489987661675,"decrypted":true}]
期望的操作
AGMDAQo1/wSsCPU=
AWa2AQo2CQSsCNE=
码
using (var stream = resp.GetResponseStream())
{
var reader = new StreamReader(stream, encoding);
var responseString = reader.ReadToEnd();
var Pirs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AssetDetail>>(responseString).OrderByDescending(AssetDetail=>AssetDetail.timestamp).Take(10);
foreach (var item in Pirs)
{
}
答案 0 :(得分:1)
为什么不提供Where
条款?你还没有提到你在你的例子中打印到控制台的确切内容,但应该是这样的:
var items = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AssetDetail>>(responseString);
var eligibleItems = items.Where(a => !a.dataFrame.EndsWith("AAAAAAAAAAA="))
.GroupBy(a => a.dataFrame)
.Select(g=> g.First())
.OrderByDescending(a => a.timestamp)
.Take(10);