问题描述
JSON.NET JsonObjectAttribute
具有属性 Id
.它是从 JsonContainerAttribute
继承的.我找不到,因为使用了Id
属性是什么?
JSON.NET JsonObjectAttribute
has a property Id
. It's inherited from the JsonContainerAttribute
. I cannot find, for what is the Id
property is used?
推荐答案
它由 Json.NET架构覆盖默认的 "$id"
属性值为类型生成模式.
It's used by Json.NET Schema to override the default "$id"
property value when generating a schema for a type.
例如如果我有以下类型:
E.g. if I have the following type:
[JsonObject(Id = "http://foo.bar/schemas/rootobject.json")]
public class RootObject { }
并使用 JSchemaGenerator
自动生成模式如下:
And auto-generate a schema using JSchemaGenerator
as follows:
var schema = new JSchemaGenerator().Generate(typeof(RootObject)).ToString();
结果是(演示小提琴此处):
The result is (demo fiddle here):
{
"$id": "http://foo.bar/schemas/rootobject.json",
"type": "object"
}
当未覆盖时,"$id"
的值由 SchemaIdGenerationHandling
枚举.
When not overridden, the value of "$id"
is controlled by the SchemaIdGenerationHandling
enumeration.
过时的JsonSchemaGenerator
也使用了它.到 JamesNK :
这篇关于JsonObjectAttribute.Id是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!