Код: Выделить всё
{
"allOf": [
{
"if": {...},
"then": {...},
"else": {
"if": {...},
"then": {...},
"else": {
"if": {...},
"then": {...},
"else": {
... and so on
}
}
}
}
]
}
Код: Выделить всё
using (var stringReader = new StringReader(json))
using (var jsonReader = new JsonTextReader(stringReader))
{
var schema = JSchema.Load(jsonReader);
}
Я написал собственную реализацию JsonTextReader, которая не должна углубляться после достижения maxDepth:
Код: Выделить всё
class DepthLimitingJsonReader : JsonTextReader
{
private readonly int _maxDepth;
private int _currentDepth;
public DepthLimitingJsonReader(TextReader reader, int maxDepth)
: base(reader)
{
_maxDepth = maxDepth;
_currentDepth = 0;
}
public override bool Read()
{
bool result = base.Read();
if (result)
{
if (TokenType == JsonToken.StartObject || TokenType == JsonToken.StartArray)
{
_currentDepth++;
// If depth exceeds maxDepth, skip the content inside this object or array
if (_currentDepth > _maxDepth && Path.EndsWith("else"))
{
Skip();
}
}
else if (TokenType == JsonToken.EndObject || TokenType == JsonToken.EndArray)
{
_currentDepth--;
}
}
return result;
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-jschema
Мобильная версия