我正在使用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; }
}
}
答案 0 :(得分:0)
现在验证工作只是我的验证错误