我认为推荐的方法是Json-Schema web Example2中显示的方法。您需要使用一个枚举来“按值”选择架构。在您的情况下,它将类似于:
{ "type": "object", "required": [ "results" ], "properties": { "results": { "type": "array", "items": { "oneOf": [ { "$ref": "#/definitions/person" }, { "$ref": "#/definitions/company" } ] } } }, "definitions": { "person": { "properties": { "type": { "enum": [ "person" ] }, "name": {"type": "string" }, "dateOfBirth": {"type":"string"} }, "required": [ "type", "name", "dateOfBirth" ], "additionalProperties": false }, "company": { "properties": { "type": { "enum": [ "company" ] }, . . . } } }}


