我正在尝试使用 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":
[
{
...
}
]
}
]
}
]
}
]
问题属性始终可以出现在问题属性内...... 我怎样才能验证它?
谢谢您的回答
最佳答案
您可以使用$ref
来定义递归结构。
{
"type": "object",
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"questions": { "type": "array", "items": { "$ref": "#"} }
}
}
关于php - Json Schema - 验证无限递归结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39469771/