Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        // 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;
            }
        }
Ejemplo n.º 4
0
        private void Reset()
        {
            key = string.Empty;

            wantKey       = false;
            wantValue     = false;
            wantComma     = false;
            wantSemicolon = false;

            elementStack.Clear();

            parseResult = null;
            resultType  = JsonElementType.Empty;
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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;
 }
Ejemplo n.º 8
0
 public JsonElement(Dictionary <string, JsonElement> value)
 {
     this.type  = JsonElementType.OBJECT;
     this.value = value;
 }
 public JsonNodeObject(string obj)
 {
     FinishObj   = obj;
     ElementType = JsonElementType.String;
 }
Ejemplo n.º 10
0
 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));
 }
Ejemplo n.º 11
0
 public JsonElement(double value)
 {
     this.type  = JsonElementType.NUMBER;
     this.value = value;
 }
Ejemplo n.º 12
0
 public JsonElement(bool value)
 {
     this.type  = JsonElementType.BOOLEAN;
     this.value = value;
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 18
0
 public JsonElement(List <JsonElement> value)
 {
     this.type  = JsonElementType.ARRAY;
     this.value = value;
 }
 public JsonNodeObject(bool obj)
 {
     FinishObj   = obj;
     ElementType = JsonElementType.Bool;
 }