我是一名有用的助手,可以为您翻译文本。
我有一个JSON模式,其中包含一个数组,我想验证数组中的所有项,但模式只验证第一个元素,为什么模式不验证其余部分呢?
模式:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"codigoEmpresa": {
"type": "string"
},
"nombreEmpresa": {
"type": "string"
},
"planes": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"codigoPlan": {
"type": "string"
},
"nombrePlan": {
"type": "string"
},
"tipoProducto": {
"type": "integer"
}
},
"required": [
"codigoPlan",
"nombrePlan",
"tipoProducto"
]
}
]
}
},
"required": [
"codigoEmpresa",
"nombreEmpresa",
"planes"
]
}
无效的JSON:
{
"codigoEmpresa":"204",
"nombreEmpresa":"Claro",
"planes":[
{
"codigoPlan":"M-PP-Premium-30.03",
"nombrePlan":"Plan Max Premium Libre",
"tipoProducto":1
},
{
"tipoProducto":3
}
]
}
模式验证器:
https://json-schema-validator.herokuapp.com/
在 JSON 的第二个元素中,属性 nombrePlan 和 tipoProducto 是必需的,但是模式验证器没有对它们进行验证。