コード例 #1
0
ファイル: JSONModelBuilder.cs プロジェクト: easwari/Json
        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;
        }
コード例 #2
0
ファイル: JSONModelBuilder.cs プロジェクト: easwari/Json
        private void CloseValue()
        {
            if (jsonStack.Peek() is JSONProperty)
            {
                JSONProperty jProp = (JSONProperty)jsonStack.Peek();
                if (jProp.state == JSONProperty.JSONPROPERTYSTATE.NAMESET)
                {
                    if (stringHolder.Length > 0)
                    {
                        jProp.SetValue(stringHolder.ToString());
                        stringHolder.Remove(0, stringHolder.Length);
                        TSM.SetLastToken(JSONTOKEN.STRINGVALUE);
                    }
                    else
                    {
                        throw new Exception("Incorrect JSON Syntax: Property has no value");
                    }
                }

                if (jProp.state == JSONProperty.JSONPROPERTYSTATE.COMPLETE)
                {
                    jsonStack.Peek().SetAsComplete();
                    IJSONContainer iJV = jsonStack.Pop();
                    jsonStack.Peek().AddChild(iJV);
                }
            }

            if (jsonStack.Peek() is JSONArray)
            {
                JSONArray jArr = (JSONArray)jsonStack.Peek();
                if (stringHolder.Length > 0)
                {
                    jArr.AddChild(stringHolder.ToString());
                    stringHolder.Remove(0, stringHolder.Length);
                    TSM.SetLastToken(JSONTOKEN.STRINGVALUE);
                }
            }
        }
コード例 #3
0
ファイル: JSONModelBuilder.cs プロジェクト: easwari/Json
        public void HandleColon()
        {
            if (!TSM.IsGoodForColon())
            {
                throw new Exception("Incorrect JSON Syntax: Incorrectly placed colon.");
            }

            string propertyName = stringHolder.ToString();

            stringHolder.Remove(0, stringHolder.Length);

            if (!IsPropertyNameGood(propertyName))
            {
                throw new Exception("Incorrect JSON Syntax: Incorrect property name.");
            }

            JSONProperty jProp = new JSONProperty(propertyName);

            jsonStack.Push(jProp);

            TSM.SetLastToken(JSONTOKEN.PROPERTYNAME);
            return;
        }