【发布时间】:2019-03-31 12:50:40
【问题描述】:
我想通过使用其他api根据条件订购多列表。
结果(我从其他 api 使用)
{
"returned_data": {
"data": [
{
"firstName": "FirstNameAA",
"lastName": "LastNameAA",
"product": [
{
"license": "1AS131",
"carType": "478",
"contract": "0112345",
"amounttoCurrent": 3000
}
]
},
{
"firstName": "FirstNameAA",
"lastName": "LastNameAA",
"product": [
{
"license": "2AS345",
"carType": "465",
"contract": "10234521",
"amounttoCurrent": 12000
}
]
},
{
"firstName": "FirstNameBB",
"lastName": "LastNameBB",
"product": [
{
"license": "kdf9034",
"carType": "4234",
"contract": "8995412",
"amounttoCurrent": 1000
}
]
}
]
}
}
但我想要新结果,按“firstName”对每个列表进行新排序
{
"returned_data": {
"data": [
{
"firstName": "FirstNameAA",
"lastName": "LastNameAA",
"product": [
{
"license": "1AS131",
"carType": "478",
"contract": "0112345",
"amounttoCurrent": 3000
},
{
"license": "2AS345",
"carType": "465",
"contract": "10234521",
"amounttoCurrent": 12000
}
]
},
{
"firstName": "FirstNameBB",
"lastName": "LastNameBB",
"product": [
{
"license": "kdf9034",
"carType": "4234",
"contract": "8995412",
"amounttoCurrent": 1000
}
]
}
]
}
}
代码 c#
var newResult = resReturnListData.returned_data.data.GroupBy(x => x.firstName); >>> not work.
请帮助我。非常感谢。
【问题讨论】:
-
能否请您为您的 json 展示您的课程?
-
是编译时错误还是您在 newResult 对象中没有得到任何结果?
-
如果您想订购商品,那么您的 linq 应该显示
OrderBy。请展示您尝试订购的商品。 -
什么不起作用?您无法将 json 转换为类,或者您无法将转换后的类转换为您想要的结果?
标签: c# list linq api asp.net-core