【问题标题】:How to generate a JSON schema of a model that include another model in C#如何在 C# 中生成包含另一个模型的模型的 JSON 模式
【发布时间】:2019-02-26 08:15:35
【问题描述】:

我正在使用 Json.NET Schema 从模型生成模式。 验证时我没问题:

using Newtonsoft.Json;
namespace HomeAddressSearch
{
    public class Properties
    {
        [Required]
        [JsonProperty(PropertyName = "civic_number")]
        public string CivicNumber { get; set; }

        [JsonProperty(PropertyName = "address")]
        public string Address { get; set; }

        [JsonProperty(PropertyName = "postal_code")]
        public string PostalCode { get; set; }

        [JsonProperty(PropertyName = "city_name")]
        public string CityName { get; set; }
    }
}

我使用以下内容并将用于验证的 JSON 传递给输出模式:

JSchemaGenerator generator = new JSchemaGenerator();

JSchema outputSchema = generator.Generate(typeof(Properties));

当我想在包含模型属性的模型位置上验证 JSON 时,我不知道该怎么做:

namespace HomeAddressSearch
{
    public class Place
    {
        public Place()
        {
            Properties = new Properties();
            PlaceType = new List<string>();
        }

        [Required]
        public string Id { get; set; }

        [JsonProperty(PropertyName = "text")]
        public string Text { get; set; }

        [JsonProperty(PropertyName = "place_type")]
        public List<string> PlaceType { get; set; }

        [JsonProperty(PropertyName = "properties")]
        public Properties Properties { get; set; }
    }
}

【问题讨论】:

    标签: c# json schema


    【解决方案1】:

    这只是我验证中的一个错误,现在一切正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2011-07-14
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      相关资源
      最近更新 更多