예제 #1
0
 public virtual void Add(JSONNode aItem)
 {
     Add("", aItem);
 }
예제 #2
0
 public virtual JSONNode Remove(JSONNode aNode)
 {
     return(aNode);
 }
예제 #3
0
 public override void Add(string aKey, JSONNode aItem)
 {
     m_List.Add(aItem);
 }
예제 #4
0
 public override JSONNode Remove(JSONNode aNode)
 {
     m_List.Remove(aNode);
     return(aNode);
 }
예제 #5
0
 public virtual void Add(string aKey, JSONNode aItem)
 {
 }
예제 #6
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack = new Stack <JSONNode>();
            JSONNode         ctx   = null;
            int    i         = 0;
            string Token     = "";
            string TokenName = "";
            bool   QuoteMode = false;

            while (i < aJSON.Length)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }
                    stack.Push(new JSONClass());
                    if (ctx != null)
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is JSONArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, stack.Peek());
                        }
                    }
                    TokenName = "";
                    Token     = "";
                    ctx       = stack.Peek();
                    break;

                case '[':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    stack.Push(new JSONArray());
                    if (ctx != null)
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is JSONArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, stack.Peek());
                        }
                    }
                    TokenName = "";
                    Token     = "";
                    ctx       = stack.Peek();
                    break;

                case '}':
                case ']':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }
                    if (stack.Count == 0)
                    {
                        throw new Exception("JSON Parse: Too many closing brackets");
                    }

                    stack.Pop();
                    if (Token != "")
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is JSONArray)
                        {
                            ctx.Add(Token);
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, Token);
                        }
                    }
                    TokenName = "";
                    Token     = "";
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }
                    TokenName = Token;
                    Token     = "";
                    break;

                case '"':
                    QuoteMode ^= true;
                    break;

                case ',':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }
                    if (Token != "")
                    {
                        if (ctx is JSONArray)
                        {
                            ctx.Add(Token);
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, Token);
                        }
                    }
                    TokenName = "";
                    Token     = "";
                    break;

                case '\r':
                case '\n':
                    break;

                case ' ':
                case '\t':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                    }
                    break;

                case '\\':
                    ++i;
                    if (QuoteMode)
                    {
                        char C = aJSON[i];
                        switch (C)
                        {
                        case 't': Token += '\t'; break;

                        case 'r': Token += '\r'; break;

                        case 'n': Token += '\n'; break;

                        case 'b': Token += '\b'; break;

                        case 'f': Token += '\f'; break;

                        case 'u':
                        {
                            string s = aJSON.Substring(i + 1, 4);
                            Token += (char)int.Parse(s, System.Globalization.NumberStyles.AllowHexSpecifier);
                            i     += 4;
                            break;
                        }

                        default: Token += C; break;
                        }
                    }
                    break;

                default:
                    Token += aJSON[i];
                    break;
                }
                ++i;
            }
            if (QuoteMode)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(ctx);
        }
예제 #7
0
 public static JSONNode Parse(string aJSON)
 {
     return(JSONNode.Parse(aJSON));
 }
예제 #8
0
 public JSONLazyCreator(JSONNode aNode, string aKey)
 {
     m_Node = aNode;
     m_Key  = aKey;
 }
예제 #9
0
 public JSONLazyCreator(JSONNode aNode)
 {
     m_Node = aNode;
     m_Key  = null;
 }