【发布时间】:2019-04-25 23:25:29
【问题描述】:
我有一个 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/
数组中第二个元素中的属性 nombrePlan 和 tipoProducto 是 json 所必需的,但模式验证器不会对其进行验证。
【问题讨论】:
标签: json