【发布时间】:2018-07-22 15:45:49
【问题描述】:
我想在 asp.net 的下拉列表中填充 JSON 数组数据。我的 json 数组是,
"Product": [
{
"id": 0,
"productId": 0,
"quantity": 20,
"productName": "Rawai",
"brandName": "Kamal Products",
"productCode": 0,
"brandId": 0,
"productPrice": 0
},
{
"id": 0,
"productId": 0,
"quantity": 22,
"productName": "OIL",
"brandName": "Kamal Proucts",
"productCode": 0,
"brandId": 0,
"productPrice": 0
},
{
"id": 0,
"productId": 0,
"quantity": 3,
"productName": "Ghee",
"brandName": "Kamal Products",
"productCode": 0,
"brandId": 0,
"productPrice": 0
}
]
我正在获取 URL 并从 URL 获取 JSON 数组
产品 lstProduct = new Product();
List lstBrandProduct = new List();
string urls = new System.Net.WebClient().DownloadString(urlnames);
JArray jsonArrays = JArray.Parse(urls);
for (int i = 0; i < jsonArrays.Count; i++)
{
CustomerOrder isiData = (new JavaScriptSerializer()).Deserialize<CustomerOrder>(jsonArrays[i].ToString());
for (int j = 0; j < isiData.product.Count; j++)
{
drpListBrand.DataTextField = isiData.product[j].BrandName;
}
}
我想在下拉列表中显示“产品名称”如何显示?
【问题讨论】:
-
到目前为止,您尝试了什么?您是否尝试搜索如何解析 JSON?你遇到了什么问题?如果您还没有尝试过,请问有什么问题?
-
发布的问题没有显示出研究或描述特定问题的努力。太宽泛了。
-
我在 asp.net 页面中添加了下拉列表控件,
<asp:DropDownList ID="drpListBrand" runat="server"></asp:DropDownList>,为此我在 c# 中编写代码来调用 JSON 数组 -
您应该将其反序列化为 CLR 对象并将其添加到您的列表中。
-
我更新了我的问题
标签: c# asp.net arrays drop-down-menu