C# LINQ GroupBy列表根据字典中的键在字典中在列表C中

C# LINQ GroupBy列表根据字典中的键在字典中在列表C中,c#,linq,dictionary,C#,Linq,Dictionary,我正在创建一个列表,其中包含用于从wcf服务创建Json的字典 我是这样创作的: List<Dictionary<string, Dictionary<string, Object>>> superduperList = new List<Dictionary<string, Dictionary<string, Object>>>(); [ { DepartureJ: {}, ReturnJ: {}, pricesDep

我正在创建一个列表,其中包含用于从wcf服务创建Json的字典

我是这样创作的:

List<Dictionary<string, Dictionary<string, Object>>> superduperList = new List<Dictionary<string, Dictionary<string, Object>>>();
[
{
DepartureJ: {},
ReturnJ: {},
pricesDepartureJ: {},
pricesReturnJ: {},
DepartureSegmentsJ: {},
ArrivalSegmentsJ: {}
},
...,
...,
...,
...,
...,
]
   "DepartureJ": {
        ArrivalDateTime: "2013-09-27T12:15:00",
        ArrivalDateTime_str: "12:15",
        StopQuantity: 0,
        StopQuantity_str: "Direct",
        TotalDuration: "50",
        TotalDuration_str: "0h 50mins",
        SeatsRemaining_str: "2",
        NoBag_str: "",
        NonRefundable: true,
        NonRefundable_str: "Non Refundable",
        FareBasisCode: "xxx-",
        RoutingId: "",
        GroupCompStr: "ATH-SKG-1xxxxxx-UOWA3--0",
        LineCompStr: "-2013-09xxxxxxxxxxxxxxxxxxxxxA3--3,0000000-1-0--",
        TotalAmount_From_Prices: 136.64
    }
List<each_flight> Fligths_sorted = flights.OrderBy(o => o.total_price).ToList();
起始数组是列表

第一个对象是词典词典 第一个字典中的对象也是具有键/值对字符串/对象的字典 我使用object是因为类型可以是bool、int或string 现在,最后一级的词典如下所示:

List<Dictionary<string, Dictionary<string, Object>>> superduperList = new List<Dictionary<string, Dictionary<string, Object>>>();
[
{
DepartureJ: {},
ReturnJ: {},
pricesDepartureJ: {},
pricesReturnJ: {},
DepartureSegmentsJ: {},
ArrivalSegmentsJ: {}
},
...,
...,
...,
...,
...,
]
   "DepartureJ": {
        ArrivalDateTime: "2013-09-27T12:15:00",
        ArrivalDateTime_str: "12:15",
        StopQuantity: 0,
        StopQuantity_str: "Direct",
        TotalDuration: "50",
        TotalDuration_str: "0h 50mins",
        SeatsRemaining_str: "2",
        NoBag_str: "",
        NonRefundable: true,
        NonRefundable_str: "Non Refundable",
        FareBasisCode: "xxx-",
        RoutingId: "",
        GroupCompStr: "ATH-SKG-1xxxxxx-UOWA3--0",
        LineCompStr: "-2013-09xxxxxxxxxxxxxxxxxxxxxA3--3,0000000-1-0--",
        TotalAmount_From_Prices: 136.64
    }
List<each_flight> Fligths_sorted = flights.OrderBy(o => o.total_price).ToList();
现在我的问题是,我如何根据关键的TotalAmount和Prices对外部列表进行排序,它们位于列表中每个项目的每个字典的字典中

我试过与LINQ一起使用groupby,但没有工作或不知道如何使用:s

superduperList.GroupBy(each_result=> each_result["DepartureJ"]["TotalAmount_From_Prices"]);

如果我创建了一个新列表或更改了现有列表,这是可以的。

事实上,我是以不同的方式创建的

我创建了一个自定义类来保存数据,如下所示:

public class each_flight
{
    public Dictionary<string, object> DepartureJ = new Dictionary<string, object>();
    public Dictionary<string, object> ReturnJ = new Dictionary<string, object>();
    public Dictionary<string, object> pricesDepartureJ = new Dictionary<string, object>();
    public Dictionary<string, object> pricesReturnJ = new Dictionary<string, object>();
    public Dictionary<string, object> DepartureSegmentsJ = new Dictionary<string, object>();
    public Dictionary<string, object> ArrivalSegmentsJ = new Dictionary<string, object>();

    public double total_price;

}
然后我创造了:

List<each_flight> flights = new List<each_flight>();
然后我填充列表中的对象,然后用额外的双倍总价对它们进行如下排序:

List<Dictionary<string, Dictionary<string, Object>>> superduperList = new List<Dictionary<string, Dictionary<string, Object>>>();
[
{
DepartureJ: {},
ReturnJ: {},
pricesDepartureJ: {},
pricesReturnJ: {},
DepartureSegmentsJ: {},
ArrivalSegmentsJ: {}
},
...,
...,
...,
...,
...,
]
   "DepartureJ": {
        ArrivalDateTime: "2013-09-27T12:15:00",
        ArrivalDateTime_str: "12:15",
        StopQuantity: 0,
        StopQuantity_str: "Direct",
        TotalDuration: "50",
        TotalDuration_str: "0h 50mins",
        SeatsRemaining_str: "2",
        NoBag_str: "",
        NonRefundable: true,
        NonRefundable_str: "Non Refundable",
        FareBasisCode: "xxx-",
        RoutingId: "",
        GroupCompStr: "ATH-SKG-1xxxxxx-UOWA3--0",
        LineCompStr: "-2013-09xxxxxxxxxxxxxxxxxxxxxA3--3,0000000-1-0--",
        TotalAmount_From_Prices: 136.64
    }
List<each_flight> Fligths_sorted = flights.OrderBy(o => o.total_price).ToList();

所以现在可以了:

您是只想对内部字典进行排序,还是需要对外部字典进行排序?意思如果外部包含Dict1和Dict2,Dict1包含总计val 1,2,Dict2包含val 3,1。。。结果应该是什么,只是包含已排序的Dict1 1、2和Dict1、3的外部字典,还是您正在尝试对外部字典进行排序?我只想对外部列表进行排序,但这取决于内部/内部Dict的键,并且Dicts是特定的。您的字典包含对象,因此您希望将值转换为双精度。在将json解析为数据结构时,您还需要确保它存储为double。我怎样才能把它投进双倍的?双人的?还是转换成双倍?而且它总是用double填充这个值,所以它是ok的。