Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在JSON模式中创建二维数组?_Arrays_Json_Jsonschema - Fatal编程技术网

Arrays 如何在JSON模式中创建二维数组?

Arrays 如何在JSON模式中创建二维数组?,arrays,json,jsonschema,Arrays,Json,Jsonschema,如何在中编写以下二维数组?网格固定为16*13。它包含完全空的行或具有int(0-99)或空字符串等值的行 以下是该阵列的一个示例: [ [], [], [], [], [], [], ['','','','',94,78,37,78,'','','',61,71], [42,82,53,62,65,47,65,77,26,93,69,69,51], [38,07,47,06,87,90,21,41,50,24,55,45,24],

如何在中编写以下二维数组?网格固定为16*13。它包含完全空的行或具有int(0-99)或空字符串等值的行

以下是该阵列的一个示例:

[  
  [],  
  [],  
  [],  
  [],  
  [],  
  [],  
  ['','','','',94,78,37,78,'','','',61,71],
  [42,82,53,62,65,47,65,77,26,93,69,69,51],
  [38,07,47,06,87,90,21,41,50,24,55,45,24],
  [55,69,'','','',83,04,90,34,88,99,28,71],
  [11,08,91,62,'','','','',36,53,57,76,65],
  [21,85,34,62,'','','','',76,67,20,77,85],
  [72,73,34,26,'','','','',37,22,49,89,26],
  [84,11,19,84,34,53,19,08,10,12,31,62,24],
  [36,94,43,27,71,30,86,96,37,45,19,60,50],
  [31,05,27,74,10,33,22,07,03,77,82,23,50]  
]
我想知道写这篇文章最好的方法是什么


提前谢谢

好的,让我们分部分来建立这个模型

首先,网格中的单个条目,可以是空字符串,也可以是整数

{
    "oneOf": [
        {
            "enum": [""]
        },
        {
            "type": "integer",
            "minimum": 0,
            "maximum": 99
        }
    ]
}
接下来,让我们定义一行-这可以是空的,也可以是13个项目:

{
    "type": "array",
    "items": {"$ref": "#/definitions/gridCell"},
    "oneOf": [
        {"enum": [[]]}, // Alternatively: {"maxItems": 0}
        {"minItems": 13, "maxItems": 13}
    ]
}
现在,我们只需要其中16个的数组:

{
    "type": "array",
    "items": {"$ref": "#/definitions/gridRow"},
    "minItems": 16,
    "maxItems": 16,
    "definitions": {
        "gridCell": { ... schema from step #1 ... },
        "gridRow": { ... schema from step #2 ... }
    }
}

这个问题基本上归结为:“如何定义数组只包含特定类型的元素?”因为JSON没有多维数组,只有数组。一个数组中的任何给定元素都可能是另一个数组,但只有其中一些元素是完全有效的。例如,
[[1,2,3],“foo”,{}]