private static JsonObject VisitObject(ref JsonTokenizer tokenizer) { var instance = new JsonObject(); while (tokenizer.MoveNext()) { var current = tokenizer.Current; if (current.TokenType == JsonTokenType.ObjectEnd) { break; } var property = current.Value; tokenizer.MoveNext(); instance.Add(property, Visit(ref tokenizer)); } return(instance); }
private TOut Deserialize <TOut>(JsonReader reader) { _buffer ??= new StringBuilder(200); var converter = Converters.Get <TOut>(); using var tokenizer = new JsonTokenizer(reader, _buffer); if (converter.IsPrimitive) { tokenizer.MoveNext(); } return(converter.Deserialize(tokenizer)); }
public override TElement[] Deserialize(JsonTokenizer tokenizer) { // it's maybe different tokens if (tokenizer.Current.TokenType == JsonTokenType.None) { tokenizer.MoveNext(); } if (tokenizer.Current.TokenType == JsonTokenType.Null) { return(null !); } var buffer = GetBuffer(); while (tokenizer.MoveNext()) { var tokenType = tokenizer.Current.TokenType; if (tokenType == JsonTokenType.ArrayStart) { continue; } if (tokenType == JsonTokenType.ArrayEnd) { break; } var element = DeserializeElement(tokenizer); buffer.Add(element); } var result = buffer.ToArray(); ReturnBuffer(buffer); return(result); }
private static JsonData Parse(JsonReader reader) { if (_buffer == null) { _buffer = new StringBuilder(200); } var tokenizer = new JsonTokenizer(reader, _buffer); tokenizer.MoveNext(); var result = Visit(ref tokenizer); tokenizer.Dispose(); return(result); }
private static JsonArray VisitArray(ref JsonTokenizer tokenizer) { var elements = new LocalList <JsonData>(); while (tokenizer.MoveNext()) { var current = tokenizer.Current; if (current.TokenType == JsonTokenType.ArrayEnd) { break; } var element = Visit(ref tokenizer); elements.Add(element); } return(elements.Length == 0 ? JsonArray.Empty : new JsonArray(elements.ToArray())); }
private TOut Deserialize <TOut>(JsonReader reader) { if (_buffer == null) { _buffer = new StringBuilder(200); } var converter = _converters.Get <TOut>(); var tokenizer = new JsonTokenizer(reader, _buffer); if (converter.IsPrimitive) { tokenizer.MoveNext(); } var result = converter.Deserialize(ref tokenizer); tokenizer.Dispose(); return(result); }
public static JsonObject VisitObject(JsonTokenizer tokenizer) { var instance = new JsonObject(); while (tokenizer.MoveNext()) { var current = tokenizer.Current; if (current.TokenType == JsonTokenType.ObjectStart) { continue; } if (current.TokenType == JsonTokenType.ObjectEnd) { break; } var propertyValue = VisitProperty(tokenizer, out var propertyName); instance.Add(propertyName, propertyValue); } return(instance); }
public List <TElement> Deserialize(ref JsonTokenizer tokenizer) { var buffer = new LocalList <TElement>(); while (tokenizer.MoveNext()) { var token = tokenizer.Current; var tokenType = token.TokenType; // ReSharper disable once ConvertIfStatementToSwitchStatement if (tokenType == JsonTokenType.Null) { return(null); } if (tokenType == JsonTokenType.ArrayStart) { continue; } if (tokenType == JsonTokenType.ArrayEnd) { break; } var element = _elementConverter.Deserialize(ref tokenizer); buffer.Add(element); } var list = new List <TElement>(buffer.Length); foreach (var element in buffer) { list.Add(element); } return(list); }
public static JsonData Parse(JsonTokenizer tokenizer) { tokenizer.MoveNext(); return(JsonVisitor.Visit(tokenizer)); }
public static JsonData VisitProperty(JsonTokenizer tokenizer) { tokenizer.MoveNext(); return(Visit(tokenizer)); }