我有一个树形结构,我想创建一个JSON模式。
类结构
class Node {
String id;
List<Node> children = new ArrayList<>();
}
到目前为止的JSON模式:
{
"name": "node",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The node id",
"required": true
}
"children": {
"type": "array",
"items": {
//The items of array should be node ?
}
}
}
}
我的问题是我不知道该如何描述"items"
JSON中数组的内容?
在此先感谢您的回答。
只需使用JSON引用指向架构本身即可:
{
"type": "object",
"required": [ "id" ],
"properties": {
"id": {
"type": "string",
"description": "The node id"
},
"children": {
"type": "array",
"items": { "$ref": "#" }
}
}
}
该#
JSON基准装置在本质上“文件本身”。因此,这使您可以定义递归模式,如此处所示。
注意:已重写,使其符合草案v4。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句