/// <summary>
                /// Parses out a JSON property AST node with a jsonTextReader.
                /// </summary>
                /// <param name="jsonTextReader">The reader to use as a lexer / tokenizer</param>
                /// <returns>JSON property AST node</returns>
                private static ObjectProperty ParsePropertyNode(IJsonReader jsonTextReader)
                {
                    FieldNameNode fieldName = FieldNameNode.Create((ArraySegment<byte>)jsonTextReader.GetBufferedRawJsonToken());

                    // Consume the fieldname from the jsonreader
                    jsonTextReader.Read();

                    JsonTextNode value = JsonTextParser.ParseNode(jsonTextReader);
                    return new ObjectProperty(fieldName, value);
                }
Esempio n. 2
0
                /// <summary>
                /// Parses out a JSON array AST node with a jsonTextReader.
                /// </summary>
                /// <param name="jsonTextReader">The reader to use as a lexer / tokenizer</param>
                /// <returns>JSON array AST node</returns>
                private static ArrayNode ParseArrayNode(IJsonReader jsonTextReader)
                {
                    List <JsonTextNode> items = new List <JsonTextNode>();

                    // consume the begin array token
                    jsonTextReader.Read();

                    while (jsonTextReader.CurrentTokenType != JsonTokenType.EndArray)
                    {
                        items.Add(JsonTextParser.ParseNode(jsonTextReader));
                    }

                    // consume the end array token
                    jsonTextReader.Read();

                    return(ArrayNode.Create(items));
                }
Esempio n. 3
0
                /// <summary>
                /// Gets the root node of a JSON AST from a jsonTextReader.
                /// </summary>
                /// <param name="jsonTextReader">The reader to use as a lexer / tokenizer</param>
                /// <returns>The root node of a JSON AST from a jsonTextReader.</returns>
                public static JsonTextNode Parse(IJsonReader jsonTextReader)
                {
                    if (jsonTextReader.SerializationFormat != JsonSerializationFormat.Text)
                    {
                        throw new ArgumentException("jsonTextReader's serialization format must actually be text");
                    }

                    // Read past the json object not started state.
                    jsonTextReader.Read();

                    JsonTextNode rootNode = JsonTextParser.ParseNode(jsonTextReader);

                    // Make sure that we are at the end of the file.
                    if (jsonTextReader.Read())
                    {
                        throw new ArgumentException("Did not fully parse json");
                    }

                    return(rootNode);
                }