public void ParseV2(TextReader txt) { while (TryReadLine(txt, out string line)) { if (!line.StartsWith("[{") || !line.EndsWith("}]")) { OnBadLine?.Invoke(line); continue; } int ix = 0; while (ix < line.Length && line[ix] == '[') { ProcessArray(line.AsSpan(1), out int processedArrayContentsLength); if (processedArrayContentsLength == -1) { break; } ix += processedArrayContentsLength; ix += 1; // to skip closing ']' } } }
public void Parse(TextReader txt) { string line = null; while ((line = txt.ReadLine()) != null) { Thread.Sleep(100); if (!line.StartsWith("[{") || !line.EndsWith("}]")) { OnBadLine?.Invoke(line); continue; } if (line.StartsWith(@"[{""ev"":""status"",""status"":")) { OnStatus?.Invoke(line); continue; } var arrayWithoutSquareBrackets = line.AsSpan(1, line.Length - 1 - 1); // Trim '[' & ']' var array = arrayWithoutSquareBrackets; do { var ixElementStart = array.IndexOf('{') + 1; var ixElementEnd = array.IndexOf('}'); var lengthOfElement = ixElementEnd - ixElementStart; var element = array.Slice(ixElementStart, lengthOfElement); Process(element); if (ixElementEnd == array.Length - 1) { break; // no elements remaining } else // Remove element from head of array { array = array.Slice(ixElementEnd + "},".Length); } } while (array.Length > 0); // TODO } }