我正在尝试使用php的"justinrainbow/json-schema"包验证json对象。
这是我试图验证的json:
{
"questions": [
{
"type": "section",
"name": "Section one",
"questions": [
{
"type": "section",
"name": "Subsection 1.1"
"questions":[
{
"type": "section",
"name": "Subsection 1.1"
"questions":
[
{
...
}
]
}
]
}
]
}
]
questions属性总是可以出现在questions属性....中我如何验证它?
感谢您的回答
您可以使用$ref
来定义递归结构
{
"type": "object",
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"questions": { "type": "array", "items": { "$ref": "#"} }
}
}