Я пытаюсь заполнить выпадающий список из объекта JSON, возвращаемого конечной точкой, которую я вызываю. Мой код для отображения выпадающего списка начинал иметь слишком много для циклов, и я остановился, подумав, что, возможно, есть более чистый способ сделать это, которого я не знаю. Конечная точка - это проект PHP, который мне не принадлежит, поэтому я не могу ничего изменить с этой стороны.
Значение JSON, возвращаемое конечной точкой, является таким же.
{
"success":true,
"message":"Third Party Bank Account Saved Successfully",
"data":{
"approvedBankAccount":[
{
"id":31,
"name":"VICTOR ADINOVI OBAITOR",
"phone":"07087251514",
"email":"ojerindej@yahoo.co.uk",
"bankAcct":"2055083324",
"bank":{
"id":18,
"name":"United Bank For Africa",
"slug":"united-bank-for-africa",
"code":"033",
"longcode":"033153513",
"gateway":"emandate",
"active":true,
"is_deleted":null,
"symplusCode":null
},
"createdBy":{
"id":10,
"first_name":"InvestNow",
"last_name":"API",
"email":"investnow@unitedcapitalplcgroup.com",
"username":"investnow",
"is_staff":false,
"isLdap":false,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"verifiedBy":{
"id":68,
"first_name":"Charles",
"last_name":"Ajayi",
"email":"Charles.Ajayi@unitedcapitalplcgroup.com",
"username":"Charles.Ajayi@unitedcapitalplcgroup.com",
"is_staff":false,
"isLdap":true,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"isVerified":true,
"approvedBy":{
"id":68,
"first_name":"Charles",
"last_name":"Ajayi",
"email":"Charles.Ajayi@unitedcapitalplcgroup.com",
"username":"Charles.Ajayi@unitedcapitalplcgroup.com",
"is_staff":false,
"isLdap":true,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"isApproved":true,
"dateCreated":{
"date":"2020-03-26 16:02:19.714362",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateVerified":{
"date":"2020-03-26 16:02:19.714362",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateApproved":{
"date":"2020-03-26 16:02:19.714362",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateRejected":null,
"rejectedBy":null,
"rejectionReason":null,
"approvedReason":"Confirmed"
},
{
"id":32,
"name":"OBAITOR , VICTOR ADINOYI",
"phone":"07087251514",
"email":"ojerindej@yahoo.co.uk",
"bankAcct":"0158140305",
"bank":{
"id":9,
"name":"Guaranty Trust Bank",
"slug":"guaranty-trust-bank",
"code":"058",
"longcode":"058152036",
"gateway":"ibank",
"active":true,
"is_deleted":null,
"symplusCode":null
},
"createdBy":{
"id":10,
"first_name":"InvestNow",
"last_name":"API",
"email":"investnow@unitedcapitalplcgroup.com",
"username":"investnow",
"is_staff":false,
"isLdap":false,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"verifiedBy":{
"id":68,
"first_name":"Charles",
"last_name":"Ajayi",
"email":"Charles.Ajayi@unitedcapitalplcgroup.com",
"username":"Charles.Ajayi@unitedcapitalplcgroup.com",
"is_staff":false,
"isLdap":true,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"isVerified":true,
"approvedBy":{
"id":68,
"first_name":"Charles",
"last_name":"Ajayi",
"email":"Charles.Ajayi@unitedcapitalplcgroup.com",
"username":"Charles.Ajayi@unitedcapitalplcgroup.com",
"is_staff":false,
"isLdap":true,
"mustChangePassword":null,
"failedLoginCount":null,
"lastLoginAttemptTime":null,
"is_activated":true
},
"isApproved":true,
"dateCreated":{
"date":"2020-03-26 17:05:17.320064",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateVerified":{
"date":"2020-03-26 17:05:17.320064",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateApproved":{
"date":"2020-03-26 17:05:17.320064",
"timezone_type":3,
"timezone":"Africa\/Lagos"
},
"dateRejected":null,
"rejectedBy":null,
"rejectionReason":null,
"approvedReason":"Confirmed"
}
],
"unverifiedBankAccount":[
]
}
}
Вот как я пытался сделать это на странице просмотра
<select class="browser-default" required>
<option value="">Select Account</option>
@for (int i = 0; i < thirdPartydropdownList.Count; i++)
{
KeyValuePair<string, object[]> entry = thirdPartydropdownList.ElementAt(i);
for (int j = 0; j < entry.Value.Length; j++)
{
var value = entry.Value[j].ToString();
Dictionary<string, string> parts = new Dictionary<string, string>();
value.Split(',').ToList().ForEach(m =>
{
var variable = m.Split('=');
});
}
}
</select>
Я считаю, что должно быть лучше сделать это. Что меня интересует, так это то, что в раскрывающемся списке указаны Id, name, BankAcct каждого JSON объекта в утвержденном массиве BankAccount. Пожалуйста, как вы будете go об этом, если вы это сделаете.
Спасибо