1
我有以下的JSON,我想知道是否有可能使用Linq做多個OrderBy
。JSON.NET與Linq的JArray中的多個orderby
var body = @"[{
""portOfLoading"": ""GOT"",
""bookingResponses"":[{
""bookingNumber"": ""11"",
""comment"": ""LOFO"",
""customerReference"": ""3423462"",
""departureDate"": ""2017-04-10"",
""departureTime"": ""18:00"",
""description"": ""desc"",
""length"": ""7482"",
""netWeight"": ""12345"",
""plugin"": ""true"",
""resourceCode"": ""CONT26"",
""route"": ""GOTZEE"",
""status"": ""Price missing"",
""unitNumber"": ""ABC123"",
""width"": ""0""
}
]
}
,
{
""portOfLoading"": ""GOT"",
""bookingResponses"":[{
""bookingNumber"": ""3"",
""comment"": ""LOFO"",
""customerReference"": ""3423462"",
""departureDate"": ""2017-04-10"",
""departureTime"": ""18:00"",
""description"": ""desc"",
""length"": ""7482"",
""netWeight"": ""12345"",
""plugin"": ""true"",
""resourceCode"": ""CONT26"",
""route"": ""GOTZEE"",
""status"": ""Price missing"",
""unitNumber"": ""ABC123"",
""width"": ""0""
}
]
}
,{
""portOfLoading"": ""OUL"",
""bookingResponses"":[{
""bookingNumber"": ""7"",
""comment"": ""STANDBY"",
""customerReference"": ""3423462"",
""departureDate"": ""2017-04-10"",
""departureTime"": ""18:00"",
""description"": ""desc"",
""length"": ""7482"",
""netWeight"": ""12345"",
""plugin"": ""true"",
""resourceCode"": ""CONT26"",
""route"": ""OULZEE"",
""status"": ""Price missing"",
""unitNumber"": ""ABC123"",
""width"": ""0""
}
]
},{
""portOfLoading"": ""ZEE"",
""bookingResponses"":[{
""bookingNumber"": ""3"",
""comment"": ""STANDBY"",
""customerReference"": ""3423462"",
""departureDate"": ""2017-04-10"",
""departureTime"": ""18:00"",
""description"": ""desc"",
""length"": ""7482"",
""netWeight"": ""12345"",
""plugin"": ""true"",
""resourceCode"": ""CONT26"",
""route"": ""ZEEGOT"",
""status"": ""Price missing"",
""unitNumber"": ""ABC123"",
""width"": ""0""
}
]
},{
""portOfLoading"": ""GOT"",
""bookingResponses"":[{
""bookingNumber"": ""10"",
""comment"": ""STANDBY"",
""customerReference"": ""3423462"",
""departureDate"": ""2017-04-10"",
""departureTime"": ""18:00"",
""description"": ""desc"",
""length"": ""7482"",
""netWeight"": ""12345"",
""plugin"": ""true"",
""resourceCode"": ""CONT26"",
""route"": ""GOTZEE"",
""status"": ""Price missing"",
""unitNumber"": ""ABC123"",
""width"": ""0""
}
]
}
]";
到目前爲止,我已經拿到了 '第一' 排序依據的工作,像這樣:
JArray jsonVal = JArray.Parse(body);
JArray sortQuery = new JArray(jsonVal.OrderBy(obj => obj["portOfLoading"]));
"portOfLoading"
後,我想排序依據"bookingNumber"
。我試過使用ThenBy
等,但從來沒有得到它的工作。由於
如果''bookingResponses'''在其下面有幾個項目會怎麼樣?你的預期產出是多少? –
你可以使用'.ThenBy(obj2 => obj2 [「bookingNumber」]'我想。 – Achilles
@Achilles你不能,看吉拉德的答案爲什麼這是不夠的。 –