【发布时间】: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; }
}
}
【问题讨论】: