我想从dynamic类型的对象中提取
JSON模式(
as defined here).
This is the best example I could find.
但是JSON.NET的Schema Generator需要查看实际的类/类型才能生成模式.
任何人对如何从动态对象中提取模式有任何想法?
解决方法
您仍然可以使用JSON.NET从动态对象中提取JSON模式.你只需要一个动态类型的实际对象就可以做到这一点.请尝试以下示例:
dynamic person = new { Id = 1,FirstName = "John",LastName = "Doe" }; JsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator {}; JsonSchema schema = schemaGenerator.Generate(person.GetType());
生成的JSON模式应如下所示:
{ "type": "object","additionalProperties": false,"properties": { "Id": { "required": true,"type": "integer" },"FirstName": { "required": true,"type": [ "string","null" ] },"LastName": { "required": true,"null" ] } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。