【发布时间】:2020-02-03 22:47:26
【问题描述】:
我有一个返回产品列表的 SQL Server 存储过程。我正在使用repeater 在我的网页中显示数据。这一切都很好,并且行很好地返回。但是,对于每个产品,我都想获得一个功能列表,例如:
ProductID, Name, Features
1, T-Shirt, "Blue, Long sleeved, 100% cotton"
2, Jeans, "Blue, Denim, Stonewashed"
理想情况下,我想对我的 proc 进行一次数据库调用,以一次性返回所有产品及其功能。所以,我认为我需要 proc 返回三列(ProductID、ProductName、Features),其中 features 列是 JSON 数组。
我对 asp.net 非常陌生,甚至对 JSON 也很陌生。我正在使用 c# 并且在 HTML 页面中,我已经能够让 ProductName 和 ProductID 方面工作得很好。我希望它看起来像这样(ul 标签部分是功能):
<div class="card-description"><%# Eval("ProductName") %><br><br>
<ul>
<li>Lightweight textured fabric</li>
<li>Rounded v-neckline</li>
<li>100% cotton</li>
</ul><br><br>
Product code: <strong><%# Eval("ProductID") %></strong>
</div>
那么我的问题是 (a) 这是最好的方法吗,以及 (b) 我如何逐行反序列化 JSON?
我是不是走错了路?
【问题讨论】:
-
为什么不让存储过程返回一个 CSV?使用 JSON 的理由是什么?
-
请让我们看看这些记录来自哪里的表模式和一些代码隐藏源,以便可以相应地修复它。
标签: c# asp.net asprepeater