【发布时间】:2021-02-04 17:31:07
【问题描述】:
我有一个对象模型想要显示为 json 字符串,例如:
public class SectionD
{
public string InsertID { get; set; }
public int CaseReference { get; set; }
public string AdditionalInfo { get; set; }
public DateTime CreationDate { get; set; }
}
我想将其呈现为 json 对象,如下所示:
{
"class": "SectionD",
"parameters": [
{
"key": "InsertID",
"type": "string"
},
{
"key": "CaseReference",
"type": "int"
},
{
"key": "AdditionalInfo",
"type": "string"
},
{
"key": "CreationDate",
"type": "DateTime"
}
]
}
数据以 json 字符串的形式存储在数据库中,我想向将对该数据进行数据库视图的人提供字段和类型的列表。
google 提供了很多用于查询模型内容的命中,但我找不到任何可以查看对象本身的内容。
谢谢
【问题讨论】:
-
最好使用 json 模式 - newtonsoft.com/jsonschema
-
您可以通过reflection 执行此操作,或者直接在此处显示dotnetfiddle.net/f9zy8L,或使用Json.NET 的合同解析器,如下所示:dotnetfiddle.net/JP6PMr。这就是你要问的全部吗?