示例#1
0
 public JSONLazyCreator(JSONNode aNode)
 {
     this.m_Node = aNode;
     this.m_Key  = null;
 }
示例#2
0
 public JSONLazyCreator(JSONNode aNode, string aKey)
 {
     this.m_Node = aNode;
     this.m_Key  = aKey;
 }
示例#3
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack      = new Stack <JSONNode>();
            JSONNode         ctx        = null;
            int           i             = 0;
            StringBuilder Token         = new StringBuilder();
            string        TokenName     = "";
            bool          QuoteMode     = false;
            bool          TokenIsQuoted = false;

            while (i < aJSON.Length)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    stack.Push(new JSONObject());
                    if (ctx != null)
                    {
                        ctx.Add(TokenName, stack.Peek());
                    }
                    TokenName    = "";
                    Token.Length = 0;
                    ctx          = stack.Peek();
                    break;

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

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

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

                    stack.Pop();
                    if (Token.Length > 0)
                    {
                        ParseElement(ctx, Token.ToString(), TokenName, TokenIsQuoted);
                        TokenIsQuoted = false;
                    }
                    TokenName    = "";
                    Token.Length = 0;
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    TokenName     = Token.ToString().Trim();
                    Token.Length  = 0;
                    TokenIsQuoted = false;
                    break;

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

                case ',':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    if (Token.Length > 0)
                    {
                        ParseElement(ctx, Token.ToString(), TokenName, TokenIsQuoted);
                        TokenIsQuoted = false;
                    }
                    TokenName     = "";
                    Token.Length  = 0;
                    TokenIsQuoted = false;
                    break;

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

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

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

                        case 'r':
                            Token.Append('\r');
                            break;

                        case 'n':
                            Token.Append('\n');
                            break;

                        case 'b':
                            Token.Append('\b');
                            break;

                        case 'f':
                            Token.Append('\f');
                            break;

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

                        default:
                            Token.Append(C);
                            break;
                        }
                    }
                    break;

                default:
                    Token.Append(aJSON[i]);
                    break;
                }
                ++i;
            }
            if (QuoteMode)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(ctx);
        }
示例#4
0
 public override JSONNode Remove(JSONNode aNode)
 {
     m_List.Remove(aNode);
     return(aNode);
 }
示例#5
0
 public static JSONNode Parse(string aJSON)
 {
     return(JSONNode.Parse(aJSON));
 }
示例#6
0
 public virtual JSONNode Remove(JSONNode aNode)
 {
     return(aNode);
 }
示例#7
0
 public JSONLazyCreator(JSONNode aNode)
 {
     m_Node = aNode;
     m_Key  = null;
 }
示例#8
0
 public virtual void Add(JSONNode aItem)
 {
     Add("", aItem);
 }
示例#9
0
 public virtual void Add(string aKey, JSONNode aItem)
 {
 }