【发布时间】:2020-04-04 07:22:27
【问题描述】:
我想在我的 .NET 代码中实现以下 JSON 结构,但我似乎无法从我的数据库中正确创建数组 [Attributes]。
您如何最好地设置这样的嵌套 Json?
{
"productid": 0,
"active": true,
"activepos": true,
"title": "Test",
"sku": "7777766666",
"deliverystatus": "",
"moneyprice": "1590.00",
"moneypriceorg": "0.00",
"moneypricein": "8.00",
"moneyofferprice": "0.00",
"friendly": "This is Friendly",
"barcode": "",
"attributes": [ "Casual", "Green" ]
}
这是我的课程,我应该为此单独开设一个课程吗?以及如何加入类来构建嵌套的 JSON?
public class ProductSQL
{
public string sku { get; set; }
public string title { get; set; }
public string description { get; set; }
public string moneypricein { get; set; }
public string moneyprice { get; set; }
public string ean { get; set; }
public string [] attributes { get; set; }
}
在我的 SQL 数据库中,我有五列 attribute 1, attribute 2, attribute 3, attribute 4, attribute 5。
我假设一个单独的属性类有五列,然后应该连接?
任何关于最佳实践 JSON 构建的建议将不胜感激。这是一个放置请求。
【问题讨论】:
-
“在我的 SQL 数据库中,我有五列” - 总是弹出这样的坏主意。单独的表。说真的,它被称为 RELATIONAL 数据库,而不是“一个文件数据库”。在此处使用关系,否则您将为此付出代价。当人们遇到非关系数据结构的问题时,每隔一周就会出现一次。
-
我知道这一点,但是考虑如何将它作为一行解析为 json 对象,这是我的问题。我可以拥有世界上所有的关系。但我无法在.net 中解析同一产品的两行。如果您对 json 和使用来自 sql 的数据有任何经验,我将不胜感激。