/// <summary> /// Parses Json value or property. /// </summary> /// <returns>Parsed value.</returns> public JsonValue ParseValueOrProperty() { JsonValue value = this.ParseValue(); JsonPrimitiveValue stringValue = value as JsonPrimitiveValue; if (stringValue != null && stringValue.Value != null && stringValue.Value is string) { if (this.tokenizer.HasMoreTokens()) { JsonPrimitiveValueTextAnnotation textAnnotation = stringValue.GetAnnotation<JsonPrimitiveValueTextAnnotation>(); JsonPropertyNameTextAnnotation propertyNameTextAnnotation = null; if (textAnnotation != null) { propertyNameTextAnnotation = new JsonPropertyNameTextAnnotation() { Text = textAnnotation.Text }; } return this.ParsePropertyWithName((string)stringValue.Value, propertyNameTextAnnotation); } else { return stringValue; } } else { return value; } }
/// <summary> /// Parses the property name as string /// </summary> /// <returns>Parsed name.</returns> private string ParseName(out JsonPropertyNameTextAnnotation nameTextAnnotation) { string result = (string)this.tokenizer.Value; nameTextAnnotation = new JsonPropertyNameTextAnnotation() { Text = this.tokenizer.TokenText }; this.tokenizer.GetNextToken(); return result; }
/// <summary> /// Parses a property starting with the colon after the property name. /// </summary> /// <param name="propertyName">The name of the property.</param> /// <param name="propertyNameTextAnnotation">The name text annotation for the property.</param> /// <returns>parsed object</returns> private JsonProperty ParsePropertyWithName(string propertyName, JsonPropertyNameTextAnnotation propertyNameTextAnnotation) { // Each name is followed by : (colon) ExceptionUtilities.Assert(this.tokenizer.TokenType == JsonTokenType.Colon, "Invalid Token"); var nameValueSeparatorTextAnnotation = new JsonPropertyNameValueSeparatorTextAnnotation() { Text = this.tokenizer.TokenText }; this.tokenizer.GetNextToken(); // Colon is followed by a value ExceptionUtilities.Assert(this.IsValueType(this.tokenizer.TokenType), "Invalid Token"); JsonValue value = this.ParseValue(); var property = new JsonProperty(propertyName, value); property.SetAnnotation(propertyNameTextAnnotation); property.SetAnnotation(nameValueSeparatorTextAnnotation); return property; }