如果JSON数组从0开始,它不会将其视为对象

2024-04-25 17:53:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我在数据库的json列中保存了以下JSON数组:

{
    "0": {
        "h": "500",
        "w": "400",
        "x": "300",
        "y": "200"
    },
    "1": {
        "h": "500",
        "w": "400",
        "x": "350",
        "y": "100"
    }
}

在我的Swagger.yml文件中,对于正文,我有以下内容:

parameters:
        - in: body
          name: body
          description: bla bla
          required: true
          schema:
            type: object
            required:
              - coordinates
            properties:
              coordinates:
                type: object
                items:
                  type: object
                  items:
                    type: number

如果我提交这个,我的Python应用程序会出现以下错误:

validation error: [{'h': '500', 'w': '400', 'x': '300', 'y': '200'}, {'h': '500', 'w': '400', 'x': '350', 'y': '100'}] is not of type 'object'

如果我将数据库中的原始JSON数组更改为从“1”开始,例如:

{
    "1": {
        "h": "500",
        "w": "400",
        "x": "300",
        "y": "200"
    },
    "2": {
        "h": "500",
        "w": "400",
        "x": "350",
        "y": "100"
    }
}

它被成功地接收为:

{"1": {"h": "500", "w": "400", "x": "300", "y": "200"}, "2": {"h": "500", "w": "400", "x": "350", "y": "100"}}

我做错什么了


Tags: 文件数据库jsonobjectymltypeswaggerrequired

热门问题