JsonObjectAttribute.Id是什么? [英] For what is the JsonObjectAttribute.Id?

查看:97
本文介绍了JsonObjectAttribute.Id是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 :

它已由JsonSchemaGenerator使用,但已弃用.

It was used by JsonSchemaGenerator but that is deprecated.

这篇关于JsonObjectAttribute.Id是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆