private void InsertNode(object obj, JsonElementType type) { int stackCount = elementStack.Count; if (stackCount > 0) { if (wantValue) { FillValue(obj, type); } else { List <object> list = (List <object>)elementStack.Peek().element; list.Add(obj); wantComma = true; } } if (type == JsonElementType.Array || type == JsonElementType.Dictionary) { elementStack.Push(new JsonElement() { element = obj, type = type }); } else if (stackCount == 0) { parseResult = obj; resultType = type; } }
private static JsonFinishNode GetJsonFinishNode(JsonElementType elem) { switch (elem) { case JsonElementType.Bool: return(JsonFinishNode.Finish); case JsonElementType.Dictionary: return(JsonFinishNode.Dict); case JsonElementType.Double: return(JsonFinishNode.Finish); case JsonElementType.List: return(JsonFinishNode.List); case JsonElementType.Long: return(JsonFinishNode.Finish); case JsonElementType.Null: return(JsonFinishNode.Finish); case JsonElementType.String: return(JsonFinishNode.Finish); default: return(JsonFinishNode.Null); } }
// Constructors for each allowed type. public JsonElement(JsonElementType type) { switch (this.type = type) { case JsonElementType.OBJECT: this.value = new Dictionary <string, JsonElement> (); break; case JsonElementType.ARRAY: this.value = new List <JsonElement> (); break; case JsonElementType.STRING: this.value = null; break; case JsonElementType.NUMBER: this.value = 0; break; case JsonElementType.BOOLEAN: this.value = false; break; } }
private void Reset() { key = string.Empty; wantKey = false; wantValue = false; wantComma = false; wantSemicolon = false; elementStack.Clear(); parseResult = null; resultType = JsonElementType.Empty; }
private void FinishNode() { JsonElement element = elementStack.Pop(); if (elementStack.Count == 0) { parseResult = element.element; resultType = element.type; } else { wantKey = false; wantValue = false; wantComma = true; wantSemicolon = false; } }
private void FillValue(object obj, JsonElementType type) { Dictionary <string, object> dict = (Dictionary <string, object>)elementStack.Peek().element; try { dict.Add(key, obj); } catch (ArgumentException e) { throw new InvalidJsonException("Json Parser: reduplicated key: \"" + key + "\", offset " + idx, e); } wantKey = false; wantValue = false; wantComma = true; wantSemicolon = false; }
public JsonNodeObject(long obj) { FinishObj = obj; ElementType = JsonElementType.Long; }
public JsonElement(Dictionary <string, JsonElement> value) { this.type = JsonElementType.OBJECT; this.value = value; }
public JsonNodeObject(string obj) { FinishObj = obj; ElementType = JsonElementType.String; }
public static T ThrowJsonTypeMismatchException <T>(JsonElementType jsonTypeThis, JsonElementType jsonTypeOther) { throw new JsonException(JsonExceptionType.TypeMismatch, string.Format("Json value '{0}' could not be converted to '{1}'", jsonTypeThis, jsonTypeOther)); }
public JsonElement(double value) { this.type = JsonElementType.NUMBER; this.value = value; }
public JsonElement(bool value) { this.type = JsonElementType.BOOLEAN; this.value = value; }
public JsonElement(string value) { this.type = JsonElementType.STRING; this.value = value; }
public JsonNodeObject(double obj) { FinishObj = obj; ElementType = JsonElementType.Double; }
public JsonNodeObject(Dictionary <string, object> obj) { FinishObj = obj; ElementType = JsonElementType.Dictionary; }
public JsonNodeObject(List <object> obj) { FinishObj = obj; ElementType = JsonElementType.List; }
public JsonNodeObject(JsonNodeObject node) { FinishObj = node.FinishObj; ElementType = node.ElementType; }
public JsonElement(List <JsonElement> value) { this.type = JsonElementType.ARRAY; this.value = value; }
public JsonNodeObject(bool obj) { FinishObj = obj; ElementType = JsonElementType.Bool; }