【发布时间】:2015-12-17 12:15:40
【问题描述】:
提前致谢。
我是 JSON 和 JSON 模式的新手。试图为元组数组生成 JSON 模式。但它不会像循环一样验证所有相似类型的元组的多个记录。 下面是 json 示例。
{
"Data":
[
[ 100, "Test", 2.5 ],
[ 101, "Test1", 3.5]
]
}
我已使用站点 jsonschema.net 生成架构,如下所示
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://jsonschema.net",
"type": "object",
"properties": {
"Data": {
"id": "http://jsonschema.net/Data",
"type": "array",
"items": [
{
"id": "http://jsonschema.net/Data/0",
"type": "array",
"items": [
{
"id": "http://jsonschema.net/Data/0/0",
"type": "integer"
},
{
"id": "http://jsonschema.net/Data/0/1",
"type": "string"
},
{
"id": "http://jsonschema.net/Data/0/2",
"type": "number"
}
],
"required": [
"0",
"1",
"2"
]
},
{
"id": "http://jsonschema.net/Data/1",
"type": "array",
"items": [
{
"id": "http://jsonschema.net/Data/1/0",
"type": "integer"
},
{
"id": "http://jsonschema.net/Data/1/1",
"type": "string"
},
{
"id": "http://jsonschema.net/Data/1/2",
"type": "number"
}
]
}
],
"required": [
"0",
"1"
]
}
},
"required": [
"Data"
]
}
如果您看到,它正在为每个相似类型的元组创建模式。请帮助我创建一个模式以通用方式验证每个元组。元组数可能会有所不同。
【问题讨论】:
标签: javascript json json.net jsonschema