Użyj JSON.NET do wygenerowania schematu JSON z dodatkowymi atrybutami
Korzystam z JSON.NET do generowania schematu JSON z klasy obiektów c #. Ale nie mogłem dodać żadnych innych atrybutów schematu json, np. maxLength, wzorzec (wyrażenie regularne do sprawdzania poprawności wiadomości e-mail) itp
Poniżej znajduje się mój działający kod, mogę wygenerować tylko schemat json z wymaganym atrybutem. Byłoby wspaniale, gdyby ktoś mógł opublikować przykład kodu, aby dodać dodatkowy atrybut dla schematu json.
Dzięki,
mój przykład kodu
<code>public class Customer { [JsonProperty(Required = Required.Always)] public int CustomerID { get; set; } [JsonProperty(Required = Required.Always)] public string FirstName { get; set; } [JsonProperty(Required = Required.Always)] public string LastName { get; set; } [JsonProperty(Required = Required.Always)] public string Email { get; set; } [JsonProperty(Required = Required.AllowNull)] public string Phone { get; set; } } </code>
do
<code>{ "title" : "Customer", "type" : "object", "properties" : { "CustomerID" : { "required" : true, "type" : "integer" }, "FirstName" : { "required" : true, "type" : "string" }, "LastName" : { "required" : true, "type" : "string" }, "Email" : { "required" : true, "type" : "string" }, "Phone" : { "required" : true, "type" : [ "string", "null" ] } } } </code>