我正在尝试创建一个允许属性为对象或null的模式。这是否可以使用当前的JSON.NET验证器?或者我的架构定义是否错误定义?任何帮助/指针将不胜感激。我通过模式缩小来表达当前的问题。
Schema definition
{ "type": "object", "$schema": "http://json-schema.org/draft-03/schema", "id": "innerobj", "additionalProperties": false, "properties": { "_id": { "type": [ "string", "null" ] } } }</value>
{ "type": "object", "$schema": "http://json-schema.org/draft-03/schema", "id": "itemobj", "additionalProperties": false, "properties": { "name": { "type": "string" }, "inner": { "type": [ {"$ref":"innerobj", "null" ] } } }</value>
{ "type": "array", "$schema": "http://json-schema.org/draft-03/schema", "id": "itemobjs", "items": {"$ref": "itemobj"} }</value>
{ "type": "object", "$schema": "http://json-schema.org/draft-03/schema", "id": "outerobj", "additionalProperties": false, "properties": { "name": { "type": "string" }, "objarray": { "type": [ {"$ref":"itemobjs", "null" ] } } }</value>
Test JSON strings
{"name":"Default","objarray":null}
{"name":"Default","objarray":[{"name":"arrDefault","inner":null}]}
{"name":"Default","objarray":[{"name": "arrDefault","inner":{"_id":null}}]}
{"name":"Default","objarray":[{"name": "arrDefault","inner":{"_id":"idDefault"}}]}
谢谢, Phil Doragh