我有一个 json 数组。元素格式可能如下:
{
"CKey": "S2_123_45_20130416105655",
"TimeOfCall": "2013-04-17T06:00:00-04:00",
"DestinationNumber": "123456789",
"CallType": "X",
"CardNumber": ""
}
数组中有很多元素,我只想要TimeOfCall(DateTime format)
24 小时内的最新三个订单。它们可能什么都不是,也可能是 1,2。最大值是3。
原来我想用几个字典来存储和排序,但它太复杂了。
更新:
此 json 数组来自 C# 代码的 json 字符串:
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<CallDataDTO>));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response4.Content.ReadAsStringAsync().Result));
calls = (List<CallDataDTO>)ser.ReadObject(ms); // dynamic
jsonStr4 = _dynamicConvert.DynamicToString(calls);// convert dynamic to string
jsonArray4 = JArray.Parse(jsonStr4); // convert string to a json array.
更新2:
?jsonArray4
{[
{
"CKey": "P2_123_23_20130416105655",
"TimeOfCall": "2013-04-17T06:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
},
{
"CKey": "P5_123_105_20130412154035",
"TimeOfCall": "2013-04-17T07:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
},
{
"CKey": "P5_123_114_20130412154000",
"TimeOfCall": "2013-04-07T08:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
}
]}
base {Newtonsoft.Json.Linq.JContainer}: {[
{
"CKey": "P2_123_23_20130416105655",
"TimeOfCall": "2013-04-17T06:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
},
{
"CKey": "P5_123_105_20130412154035",
"TimeOfCall": "2013-04-17T07:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
},
{
"CKey": "P5_123_114_20130412154000",
"TimeOfCall": "2013-04-07T08:00:00-04:00",
"DestinationNumber": "1234567890",
"CallType": "DEBIT",
"CardNumber": ""
}
]}
Type: Array