【发布时间】:2018-09-02 11:12:48
【问题描述】:
考虑我在下拉列表中有以下值(dropDownList 变量),用户选择的值在selectedDropDownValues 列表中。
DB api 返回客户列表(customerDBList 变量)。
现在的要求是从下面提到的选定值构建 JSON -
var dropDownList = new[] { "Customer.Id", "Customer.FirstName", "Customer.LastName", "Customer.Address.AddressLine1", "Customer.Address.AddressLine2" };
var selectedDropDownValues = new[] { "Customer.Id", "Customer.FirstName", "Customer.Address.AddressLine1" };
var customerDBList = new List<Customer>(){
new Customer {
Id=1,
FirstName="John",
LastName="Desouza",
Address=new Address{
AddressLine1="1 Street",
AddressLine2="Linking Road"
}},
new Customer {
Id=2,
FirstName="Sam",
LastName="Lewis",
Address=new Address{
AddressLine1="Fedral Highway",
AddressLine2="Louisville"
}
}};
预期的 JSON 输出为 -
[
{
"Customer": {
"Id": 1,
"FirstName": "John",
"Address": {
"AddressLine1": "1 Street"
}
}
},
{
"Customer": {
"Id": 2,
"FirstName": "Sam",
"Address": {
"AddressLine1": "Fedral Highway"
}
}
}
]
【问题讨论】:
-
您能否澄清一下您是否希望将两条地址线放在一起?您的示例显示了这两种方式。
-
不,我想要根据 selectedDropDownValues 中的选定值
-
我已经更新了 JSON。