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
Json模式-如何表示混合类型(字符串和对象)的字段?_Json_Jsonschema_Json Schema Validator - Fatal编程技术网

Json模式-如何表示混合类型(字符串和对象)的字段?

Json模式-如何表示混合类型(字符串和对象)的字段?,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,我在数据中有一个字段,可以多次键入: 它可以是type=string,具有以下架构: {"mixed_field" : {"type":"string"} } 其他情况下,它可能是type=object,架构如下所示: {"mixed_field" : { "properties": { "access_token": { "type": "string" }, "created_at": { "type": "integer" }

我在数据中有一个字段,可以多次键入:

它可以是type=string,具有以下架构:

{"mixed_field" : {"type":"string"} }
其他情况下,它可能是type=object,架构如下所示:

{"mixed_field" : {
  "properties": {
    "access_token": {
      "type": "string"
    },
    "created_at": {
      "type": "integer"
    }
  },
  "type": "object"
  }
}
如何表示“混合_字段”可以是类型字符串或类型对象?我应该使用下面的“oneOf”关键字吗

{
  "mixed_field": {
    "oneOf": [
      {
        "type": "string"
      },
      {
        "properties": {
          "access_token": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        },
        "type": "object"
      }
    ]
  }
}

您可以使用/anyOf或
“type”:[“string”,“object”]
,如果是字符串,“properties”关键字将被忽略。

不知道如果type是基元,“properties”将被忽略!谢谢你的提醒。使用关键字与枚举类型字段相比,是否有特定的偏好?