Esempio n. 1
0
        public void HandlePrimitiveValue(object primitiveVal)
        {
            if (!TSM.IsGoodForPrimitives())
            {
                throw new Exception("Incorrect JSON Syntax: Incorrectly placed primitive value.");
            }

            if (jsonStack.Count == 0)
            {
                JSONEmptyContainer jEmpty = new JSONEmptyContainer();
                jEmpty.AddChild(primitiveVal);
                jEmpty.SetAsComplete();
                jsonStack.Push(jEmpty);
            }
            else if (jsonStack.Peek() is JSONProperty)
            {
                JSONProperty jProp = (JSONProperty)jsonStack.Peek();
                if (jProp.state == JSONProperty.JSONPROPERTYSTATE.NAMESET)
                {
                    jProp.SetValue(primitiveVal);
                }
            }
            else if (jsonStack.Peek() is JSONArray)
            {
                JSONArray jArr = (JSONArray)jsonStack.Peek();
                jArr.AddChild(primitiveVal);
            }
            else
            {
                throw new Exception("Incorrect JSON Syntax: Incorrectly placed primitive value. List of primitives not placed in array or object.");
            }

            TSM.SetLastToken(JSONTOKEN.PRIMITIVEVALUE);
            return;
        }
Esempio n. 2
0
        public IJSONContainer HandleEndOfText()
        {
            if (stringHolder.Length > 0)
            {
                if (jsonStack.Count == 0)
                {
                    JSONEmptyContainer jEmpty = new JSONEmptyContainer();
                    jEmpty.AddChild(stringHolder.ToString());
                    jEmpty.SetAsComplete();
                    jsonStack.Push(jEmpty);
                }
                else
                {
                    throw new Exception("Incorrect JSON Syntax: Incomplete JSON Text.");
                }
            }

            if (jsonStack.Count > 1)
            {
                throw new Exception("Incorrect JSON Syntax: Incomplete JSON Text.");
            }

            if (!jsonStack.Peek().IsComplete())
            {
                throw new Exception("Incomplete object/array.");
            }

            return(jsonStack.Pop());
        }