/// <inheritdoc /> public JsonItem ParseNext() { JsonString propertyName = null; string propertyNameAsString; IDictionary <string, JsonItem> propertyBag = new Dictionary <string, JsonItem>(); this.state = JsonObjectParseState.Start; while (this.state != JsonObjectParseState.End) { JsonItem item = null; switch (this.state) { case JsonObjectParseState.Start: if (this.Consume('{')) { this.state = JsonObjectParseState.PropertyName; new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); } else { return(this.MakeError('{')); } break; case JsonObjectParseState.PropertyName: if (this.Peek('"')) { item = new JsonStringParser(this.Buffer).ParseNext(); if (item.IsString) { propertyName = (JsonString)item; } else { return(item); } new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.KeyValueSperator; } else if (this.Consume('}')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.End; } else { return(this.MakeError('"')); } break; case JsonObjectParseState.KeyValueSperator: if (this.Consume(':')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.Value; } else { return(this.MakeError(':')); } break; case JsonObjectParseState.Value: item = new JsonValueParser(this.Buffer).ParseNext(); if (item.IsError) { return(item); } propertyName.TryGetValue(out propertyNameAsString); propertyBag.Add(propertyNameAsString, item); new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.PropertySetSeperator; break; case JsonObjectParseState.PropertySetSeperator: if (this.Consume(',')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.PropertyName; } else if (this.Consume('}')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.End; } else { return(this.MakeError(',')); } break; } } return(new JsonObject(propertyBag)); }
/// <inheritdoc /> public JsonItem ParseNext() { JsonString propertyName = null; string propertyNameAsString; IDictionary<string, JsonItem> propertyBag = new Dictionary<string, JsonItem>(); this.state = JsonObjectParseState.Start; while (this.state != JsonObjectParseState.End) { JsonItem item = null; switch (this.state) { case JsonObjectParseState.Start: if (this.Consume('{')) { this.state = JsonObjectParseState.PropertyName; new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); } else { return this.MakeError('{'); } break; case JsonObjectParseState.PropertyName: if (this.Peek('"')) { item = new JsonStringParser(this.Buffer).ParseNext(); if (item.IsString) { propertyName = (JsonString)item; } else { return item; } new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.KeyValueSperator; } else if (this.Consume('}')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.End; } else { return this.MakeError('"'); } break; case JsonObjectParseState.KeyValueSperator: if (this.Consume(':')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.Value; } else { return this.MakeError(':'); } break; case JsonObjectParseState.Value: item = new JsonValueParser(this.Buffer).ParseNext(); if (item.IsError) { return item; } propertyName.TryGetValue(out propertyNameAsString); propertyBag.Add(propertyNameAsString, item); new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.PropertySetSeperator; break; case JsonObjectParseState.PropertySetSeperator: if (this.Consume(',')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.PropertyName; } else if (this.Consume('}')) { new JsonWhiteSpaceParser(JsonParseType.Object, this.Buffer).ParseNext(); this.state = JsonObjectParseState.End; } else { return this.MakeError(','); } break; } } return new JsonObject(propertyBag); }