【发布时间】:2016-12-01 09:36:15
【问题描述】:
我有一个问题,我无法自己解决。所以我想在 StackOverflow 寻求帮助。
我正在生成 XSD 并使用基于 python 的转换器将 XSD 转换为 JSON 模式。 JSON 模式用于验证 JSON 代码,我不会详细解释。我的问题是,我有 JSON 代码来验证其中包含一个数组,该数组包含包含整数的数组(复数)。
JSON 代码如下所示:
"factors": [
[12,3],
[1,14]
]
我知道如何为此编写 JSON 架构:
"factors": {
"items": {
"$ref": "#/definitions/factorscontent"
},
"type": "array"
}
...
"factorscontent": {
"items": {
"type": "integer"
},
"type": "array",
"properties": {}
}
这很好用。但我不知道如何在 XSD 中构建这种结构。有谁知道如何面对“数组中的整数”问题?
要补充一点:如果 json 代码如下所示:
"factors": [ "items":{ [12,3], [1,14] } ]
我不会有问题,因为我可以将“因子数组”的内容表示为
<xs:element name="items" type="integer" max0occurs="unbounded"/>
但是里面的数组结构只包含整数,没有元素!
【问题讨论】:
-
要补充一点:如果 json 代码看起来像这样: "factors": [ "items":{[12,3], [1,14]} ] 我不会有一个问题,因为我可以将“因子数组”的内容表示为
但是里面的数组结构只包含整数,没有元素! -
所以你的问题可以改写为如何在 XSD 中定义一个二维数组。
-
当然你的第一个 Json 结构是一个 int[][]
标签: xsd jsonschema