static void Main(string[] args) { var parser = new Parser(); var obj = parser.ParseAll( @"[ { ""foo"" : null, ""array"" : [ null, ""a"", ""b"" ] }, ""foo"" ]"); Console.WriteLine(obj); Console.ReadKey(); }
private static Parser<object> GetObjectParser(Parser<string> stringParser, MainParser mainParser) { var memberParser = from name in stringParser from colon in Parse.Char(':').Token() from value in Parse.Ref(() => mainParser.Value) select new Member { Name = name, Value = value }; var objectParser = from openBrace in Parse.Char('{').Token() from firstMember in memberParser.Optional() from otherMembers in (from comma in Parse.Char(',').Token() from member in memberParser select member).Many() from closeBrace in Parse.Char('}').Token() select GetExpandoObject(firstMember, otherMembers); return objectParser; }