Manual analysis of complex formats is not the easiest thing. You may have a lot of problems. Offhand: spaces? comments? string constants? different types of quotes? You do not want to provide for all this yourself? Therefore, it makes sense to use a ready-made parser, for example, JSON.NET.
If parsing an entire file into memory is too expensive, then you can instead parse its tokens in streaming mode. Here's an example of how to pull out all the values of the string name attributes:
using Newtonsoft.Json; class Test { public static void Main() { string json = "{ 'everything' : [ " + "{ 'name': 'dog' }, " + "{ 'trap': '\"name\" : \"snake\"' }, " + "{ \"name\" : \"elephant\"}]}"; // вам нужен будет, скорее всего, не StringReader, а StreamReader using (TextReader sr = new StringReader(json)) { foreach (var name in ExtractNames(sr)) Console.WriteLine(name); } } static IEnumerable<string> ExtractNames(TextReader tr) { using (var jsr = new JsonTextReader(tr)) { bool expectValue = false; while (jsr.Read()) { if (jsr.TokenType == JsonToken.Comment) continue; if (expectValue) { if (jsr.ValueType == typeof(string)) yield return (string)jsr.Value; expectValue = false; } else { if (jsr.TokenType == JsonToken.PropertyName && (string)jsr.Value == "name") expectValue = true; } } } } }
JsonTextReader. - VladD