c# - C# 将我的 JsonSchema 的属性转换为 Json Schema 并动态添加新字段
问题描述
我用一些标准属性创建了自己的 JsonSchema。
public class JsonSchema
{
public SchemaType Type { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Const { get; set; }
public IList<Dictionary<string, object>> Properties { get; set; }
public IList<object> Enum { get; set; }
public IList<JsonSchema> Items { get; set; }
public IList<string> Required { get; set; }
public IList<JsonSchema> AllOf { get; set; }
public IList<JsonSchema> AnyOf { get; set; }
public IList<JsonSchema> OneOf { get; set; }
}
我需要将其转换为 Json Schema 字符串。
我正在使用 JsonConvert.SerializeObject 对其进行转换。几乎一切正常,但属性“属性”正在转换为 JsonSchema 数组,如下所示:
{
"type": "object",
"properties": [
{
"f_1022": {
"type": "string",
"title": "Zona",
"oneOf": [
{
"title": "Urbana",
"description": "Urbana",
"const": "o_1043"
},
{
"title": "Rural",
"description": "Rural",
"const": "o_1044"
},
{
"title": "Periurbana",
"description": "Periurbana",
"const": "o_1045"
}
]
}
},
{
"f_1023": {
"type": "string",
"title": "Etnia/Cor"
}
},
]
}
我需要结果是这样的:
{
"type": "object",
"properties":
{
"f_1022": {
"type": "string",
"title": "Zona",
"oneOf": [
{
"title": "Urbana",
"description": "Urbana",
"const": "o_1043"
},
{
"title": "Rural",
"description": "Rural",
"const": "o_1044"
},
{
"title": "Periurbana",
"description": "Periurbana",
"const": "o_1045"
}
]
},
"f_1023": {
"type": "string",
"title": "Etnia/Cor"
}
}
}
请注意,最后一个 Json 属性没有括号。
如何让 JsonConvert 像最后一个 Json Schema 一样转换?
谢谢
解决方案
推荐阅读
- sql - HSQL - 根据 IF 条件在查询中添加新列
- javascript - 当我在移动设备(wordpress)中点击它时,汉堡菜单没有打开
- sql - 带有 unix 时间戳的 BigQuery PARSE_TIMESTAMP - 无法解析输入字符串
- ruby-on-rails - Rails 6 simple_form 接收哈希
- node.js - 将私有注册表与 .npmrc 一起使用
- excel - 循环时无法重复获取指定单元格中包含的值
- sql-server - 将表复制到数据库中
- windows - AWS Windows userdata powershell 不工作
- javascript - 引导模式弹出窗口未显示在索引页面上
- flutter - 忽略在 pubspec.yaml 中找不到资产的文件或变体