Add() публичный Метод

public Add ( JSONNode aItem ) : void
aItem JSONNode
Результат void
Пример #1
0
    /**
     * This function converts the requested stored gesture into a JSON string containing the gesture name and training data.
     *
     * Gestures exported using this function can be re-imported using the fromJSON function below.
     *
     * @param gestureName
     * @returns {String}
     */
    string toJSON(string gestureName)
    {
        var gestures = this.gestures[gestureName];


        SimpleJSON.JSONNode json = new SimpleJSON.JSONNode(),
                            name = new SimpleJSON.JSONNode(),
                            pose = new SimpleJSON.JSONNode(),
                            data = new SimpleJSON.JSONNode(),
                            x, y, z, stroke;

        foreach (var gesture in gestures)
        {
            SimpleJSON.JSONNode gesturePoints = new SimpleJSON.JSONNode();

            foreach (var point in gesture)
            {
                SimpleJSON.JSONNode pointComponents = new SimpleJSON.JSONNode();

                x      = new SimpleJSON.JSONNode(); x.AsFloat = point.x;
                y      = new SimpleJSON.JSONNode(); y.AsFloat = point.y;
                z      = new SimpleJSON.JSONNode(); z.AsFloat = point.z;
                stroke = new SimpleJSON.JSONNode(); stroke.AsFloat = point.stroke;

                pointComponents.Add("x", x);
                pointComponents.Add("y", y);
                pointComponents.Add("z", z);
                pointComponents.Add("stroke", stroke);

                gesturePoints.Add(pointComponents);
            }

            data.Add(gesturePoints);
        }


        name.Value  = gestureName;
        pose.AsBool = this.poses[gestureName];

        json.Add("name", name);
        json.Add("pose", pose);
        json.Add("data", data);

        return(json.ToString());
    }
Пример #2
0
    public void buildEntity(JsonObject configdata, ref SimpleJSON.JSONNode _data)
    {
        //获取配置数据,新数据不覆盖
        ICollection <string> npcKeys = configdata.Keys;

        foreach (string _key in npcKeys)
        {
            if (string.IsNullOrEmpty(_key))
            {
                continue;
            }
            if (_data[_key] == null)
            {
                _data.Add(_key, configdata[_key].ToString());
            }
        }
    }
Пример #3
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);
        }
Пример #4
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack      = new Stack <JSONNode>();
            JSONNode         jSONNode   = null;
            int           i             = 0;
            StringBuilder stringBuilder = new StringBuilder();
            string        aKey          = "";
            bool          flag          = false;
            bool          flag2         = false;

            for (; i < aJSON.Length; i++)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                        break;
                    }
                    stack.Push(new JSONObject());
                    if (jSONNode != null)
                    {
                        jSONNode.Add(aKey, stack.Peek());
                    }
                    aKey = "";
                    stringBuilder.Length = 0;
                    jSONNode             = stack.Peek();
                    break;

                case '[':
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                        break;
                    }
                    stack.Push(new JSONArray());
                    if (jSONNode != null)
                    {
                        jSONNode.Add(aKey, stack.Peek());
                    }
                    aKey = "";
                    stringBuilder.Length = 0;
                    jSONNode             = stack.Peek();
                    break;

                case ']':
                case '}':
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                        break;
                    }
                    if (stack.Count == 0)
                    {
                        throw new Exception("JSON Parse: Too many closing brackets");
                    }
                    stack.Pop();
                    if ((stringBuilder.Length > 0) | flag2)
                    {
                        jSONNode.Add(aKey, ParseElement(stringBuilder.ToString(), flag2));
                    }
                    flag2 = false;
                    aKey  = "";
                    stringBuilder.Length = 0;
                    if (stack.Count > 0)
                    {
                        jSONNode = stack.Peek();
                    }
                    break;

                case ':':
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                        break;
                    }
                    aKey = stringBuilder.ToString();
                    stringBuilder.Length = 0;
                    flag2 = false;
                    break;

                case '"':
                    flag   = !flag;
                    flag2 |= flag;
                    break;

                case ',':
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                        break;
                    }
                    if ((stringBuilder.Length > 0) | flag2)
                    {
                        jSONNode.Add(aKey, ParseElement(stringBuilder.ToString(), flag2));
                    }
                    flag2 = false;
                    aKey  = "";
                    stringBuilder.Length = 0;
                    flag2 = false;
                    break;

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

                case '\\':
                    i++;
                    if (flag)
                    {
                        char c = aJSON[i];
                        switch (c)
                        {
                        case 't':
                            stringBuilder.Append('\t');
                            break;

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

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

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

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

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

                        default:
                            stringBuilder.Append(c);
                            break;
                        }
                    }
                    break;

                default:
                    stringBuilder.Append(aJSON[i]);
                    break;

                case '\n':
                case '\r':
                    break;
                }
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            if (jSONNode == null)
            {
                return(ParseElement(stringBuilder.ToString(), flag2));
            }
            return(jSONNode);
        }
Пример #5
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack = new Stack <JSONNode>();
            // Used to determine node location (For example: object.childA.childB.node)
            Stack <string> locationStack = new Stack <string>();
            JSONNode       ctx           = null;
            int            i             = 0;
            StringBuilder  Token         = new StringBuilder();
            string         TokenName     = "";
            bool           QuoteMode     = false;
            bool           TokenIsQuoted = false;
            bool           ValueMode     = false;
            bool           NewLine       = 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();
                    NewLine      = false;
                    ValueMode    = false;
                    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();
                    NewLine      = false;
                    break;

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

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

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

                case '"':
                    QuoteMode ^= true;
                    // This throws a JSONParseException if one of two conditions are met:
                    // 1) A new line was detected with no proper closing symbols ("," "]" "}") to say otherwise
                    // 2) An opening quotation mark is detected when we are already writing a value
                    if (NewLine || (ValueMode && Token.Length > 0 && QuoteMode))
                    {
                        throw new JSONParseException("Node missing a required comma", locationStack, Token.ToString());
                    }
                    TokenIsQuoted |= QuoteMode;
                    break;

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

                case '\r':
                    break;

                case '\n':
                    if (ValueMode && (!string.IsNullOrEmpty(TokenName) || Token.Length > 0))
                    {
                        NewLine = true;
                    }
                    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;

                case '/':
                    if (allowLineComments && !QuoteMode && i + 1 < aJSON.Length && aJSON[i + 1] == '/')
                    {
                        while (++i < aJSON.Length && aJSON[i] != '\n' && aJSON[i] != '\r')
                        {
                            ;
                        }
                        break;
                    }
                    Token.Append(aJSON[i]);
                    break;

                case '\uFEFF':     // remove / ignore BOM (Byte Order Mark)
                    break;

                default:
                    Token.Append(aJSON[i]);
                    break;
                }
                ++i;
            }
            if (QuoteMode)
            {
                throw new JSONParseException("Quotation marks seems to be messed up", locationStack, Token.ToString());
            }
            if (ctx == null)
            {
                return(ParseElement(Token.ToString(), TokenIsQuoted));
            }
            return(ctx);
        }
Пример #6
0
        public static JSONNode Parse(string jsonString)
        {
            var      stack         = new Stack <JSONNode>();
            JSONNode ctx           = null;
            var      i             = 0;
            var      token         = new StringBuilder("");
            var      tokenName     = "";
            var      quoteMode     = false;
            var      tokenIsString = false;

            while (i < jsonString.Length)
            {
                var currentChar = jsonString[i];
                switch (currentChar)
                {
                case '{':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                        break;
                    }
                    stack.Push(new JSONClass());
                    if (ctx != null)
                    {
                        tokenName = tokenName.Trim();
                        if (ctx is JSONArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (tokenName.Length != 0)
                        {
                            ctx.Add(tokenName, stack.Peek());
                        }
                    }
                    tokenName = "";
                    token     = new StringBuilder();
                    ctx       = stack.Peek();
                    break;

                case '[':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                        break;
                    }

                    stack.Push(new JSONArray());
                    if (ctx != null)
                    {
                        tokenName = tokenName.Trim();

                        if (ctx is JSONArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (tokenName.Length != 0)
                        {
                            ctx.Add(tokenName, stack.Peek());
                        }
                    }
                    tokenName = "";
                    token     = new StringBuilder();
                    ctx       = stack.Peek();
                    break;

                case '}':
                case ']':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                        break;
                    }
                    if (stack.Count == 0)
                    {
                        throw new Exception("JSON Parse: Too many closing brackets");
                    }

                    stack.Pop();
                    if (token.Length != 0)
                    {
                        tokenName = tokenName.Trim();

                        /*
                         * if (ctx is JSONArray)
                         * ctx.Add (Token);
                         * else if (TokenName != "")
                         * ctx.Add (TokenName, Token);
                         */
                        AddElement(ctx, token.ToString(), tokenName, tokenIsString);
                        tokenIsString = false;
                    }
                    tokenName = "";
                    token     = new StringBuilder();
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                        break;
                    }
                    if (tokenName.Length > 0)
                    {
                        throw new Exception("JSON Parse: The json seems to be broken");
                    }
                    tokenName     = token.ToString();
                    token         = new StringBuilder();
                    tokenIsString = false;
                    break;

                case '"':
                    quoteMode    ^= true;
                    tokenIsString = quoteMode ? true : tokenIsString;
                    break;

                case ',':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                        break;
                    }
                    if (token.Length != 0)
                    {
                        /*
                         * if (ctx is JSONArray) {
                         * ctx.Add (Token);
                         * } else if (TokenName != "") {
                         * ctx.Add (TokenName, Token);
                         * }
                         */
                        AddElement(ctx, token.ToString(), tokenName, tokenIsString);
                        tokenIsString = false;
                    }
                    tokenName     = "";
                    token         = new StringBuilder();
                    tokenIsString = false;
                    break;

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

                case ' ':
                case '\t':
                    if (quoteMode)
                    {
                        token.Append(currentChar);
                    }
                    break;

                case '\\':
                    ++i;
                    if (quoteMode)
                    {
                        var c = jsonString[i];
                        // The sequences \/, \" and \\ we remove the backslash from when parsing
                        // for \u we convert it into the character it represents
                        // and all others we leave alone
                        switch (c)
                        {
                        case '/':
                            token.Append('/');
                            break;

                        case '"':
                            token.Append('"');
                            break;

                        case '\\':
                            token.Append('\\');
                            break;

                        case 'u':
                        {
                            var s = jsonString.Substring(i + 1, 4);
                            token.Append((char)int.Parse(
                                             s,
                                             NumberStyles.AllowHexSpecifier));
                            i += 4;
                            break;
                        }

                        default:
                            token.Append('\\');
                            token.Append(c);
                            break;
                        }
                    }
                    break;

                default:
                    if (!quoteMode)
                    {
                        // We check that we dont have illegal characters outside the quotes
                        switch (currentChar)
                        {
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                        case '0':
                        case '+':
                        case '-':
                        case 'e':
                        case 'E':
                        case '.':
                            break;

                        case 'n':
                        {
                            var s = jsonString.Substring(i, 4);
                            if (s == "null")
                            {
                                i += 4;
                                token.Append(s);
                                continue;
                            }
                            throw new Exception("Json format seems invalid");
                        }

                        case 'f':
                        {
                            var s = jsonString.Substring(i, 5);
                            if (s == "false")
                            {
                                i += 5;
                                token.Append(s);
                                continue;
                            }
                            throw new Exception("Json format seems invalid");
                        }

                        case 't':
                        {
                            var s = jsonString.Substring(i, 4);
                            if (s == "true")
                            {
                                i += 4;
                                token.Append(s);
                                continue;
                            }
                            throw new Exception("Json format seems invalid");
                        }

                        default:
                            throw new Exception("Json format seems invalid");
                        }
                    }

                    token.Append(currentChar);
                    break;
                }
                ++i;
            }
            if (quoteMode)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            if (stack.Count != 0)
            {
                throw new Exception("There are unclosed {} or [] in the string");
            }
            return(ctx);
        }
        // Token: 0x06000278 RID: 632 RVA: 0x0000B08C File Offset: 0x0000928C
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack      = new Stack <JSONNode>();
            JSONNode         jsonnode   = null;
            int           i             = 0;
            StringBuilder stringBuilder = new StringBuilder();
            string        text          = "";
            bool          flag          = false;
            bool          flag2         = false;

            while (i < aJSON.Length)
            {
                char c = aJSON[i];
                if (c <= ',')
                {
                    if (c <= ' ')
                    {
                        switch (c)
                        {
                        case '\t':
                            break;

                        case '\n':
                        case '\r':
                            goto IL_33E;

                        case '\v':
                        case '\f':
                            goto IL_330;

                        default:
                            if (c != ' ')
                            {
                                goto IL_330;
                            }
                            break;
                        }
                        if (flag)
                        {
                            stringBuilder.Append(aJSON[i]);
                        }
                    }
                    else if (c != '"')
                    {
                        if (c != ',')
                        {
                            goto IL_330;
                        }
                        if (flag)
                        {
                            stringBuilder.Append(aJSON[i]);
                        }
                        else
                        {
                            if (stringBuilder.Length > 0 || flag2)
                            {
                                JSONNode.ParseElement(jsonnode, stringBuilder.ToString(), text, flag2);
                            }
                            text = "";
                            stringBuilder.Length = 0;
                            flag2 = false;
                        }
                    }
                    else
                    {
                        flag  = !flag;
                        flag2 = (flag2 || flag);
                    }
                }
                else
                {
                    if (c <= ']')
                    {
                        if (c != ':')
                        {
                            switch (c)
                            {
                            case '[':
                                if (flag)
                                {
                                    stringBuilder.Append(aJSON[i]);
                                    goto IL_33E;
                                }
                                stack.Push(new JSONArray());
                                if (jsonnode != null)
                                {
                                    jsonnode.Add(text, stack.Peek());
                                }
                                text = "";
                                stringBuilder.Length = 0;
                                jsonnode             = stack.Peek();
                                goto IL_33E;

                            case '\\':
                                i++;
                                if (flag)
                                {
                                    char c2 = aJSON[i];
                                    if (c2 <= 'f')
                                    {
                                        if (c2 == 'b')
                                        {
                                            stringBuilder.Append('\b');
                                            goto IL_33E;
                                        }
                                        if (c2 == 'f')
                                        {
                                            stringBuilder.Append('\f');
                                            goto IL_33E;
                                        }
                                    }
                                    else
                                    {
                                        if (c2 == 'n')
                                        {
                                            stringBuilder.Append('\n');
                                            goto IL_33E;
                                        }
                                        switch (c2)
                                        {
                                        case 'r':
                                            stringBuilder.Append('\r');
                                            goto IL_33E;

                                        case 't':
                                            stringBuilder.Append('\t');
                                            goto IL_33E;

                                        case 'u':
                                        {
                                            string s = aJSON.Substring(i + 1, 4);
                                            stringBuilder.Append((char)int.Parse(s, NumberStyles.AllowHexSpecifier));
                                            i += 4;
                                            goto IL_33E;
                                        }
                                        }
                                    }
                                    stringBuilder.Append(c2);
                                    goto IL_33E;
                                }
                                goto IL_33E;

                            case ']':
                                break;

                            default:
                                goto IL_330;
                            }
                        }
                        else
                        {
                            if (flag)
                            {
                                stringBuilder.Append(aJSON[i]);
                                goto IL_33E;
                            }
                            text = stringBuilder.ToString();
                            stringBuilder.Length = 0;
                            flag2 = false;
                            goto IL_33E;
                        }
                    }
                    else if (c != '{')
                    {
                        if (c != '}')
                        {
                            goto IL_330;
                        }
                    }
                    else
                    {
                        if (flag)
                        {
                            stringBuilder.Append(aJSON[i]);
                            goto IL_33E;
                        }
                        stack.Push(new JSONObject());
                        if (jsonnode != null)
                        {
                            jsonnode.Add(text, stack.Peek());
                        }
                        text = "";
                        stringBuilder.Length = 0;
                        jsonnode             = stack.Peek();
                        goto IL_33E;
                    }
                    if (flag)
                    {
                        stringBuilder.Append(aJSON[i]);
                    }
                    else
                    {
                        if (stack.Count == 0)
                        {
                            throw new Exception("JSON Parse: Too many closing brackets");
                        }
                        stack.Pop();
                        if (stringBuilder.Length > 0 || flag2)
                        {
                            JSONNode.ParseElement(jsonnode, stringBuilder.ToString(), text, flag2);
                            flag2 = false;
                        }
                        text = "";
                        stringBuilder.Length = 0;
                        if (stack.Count > 0)
                        {
                            jsonnode = stack.Peek();
                        }
                    }
                }
IL_33E:
                i++;
                continue;
IL_330:
                stringBuilder.Append(aJSON[i]);
                goto IL_33E;
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jsonnode);
        }
Пример #8
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack    = new Stack <JSONNode>();
            JSONNode         jSONNode = null;
            int    i     = 0;
            string text  = string.Empty;
            string text2 = string.Empty;
            bool   flag  = false;

            for (; i < aJSON.Length; i++)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (flag)
                    {
                        text += aJSON[i];
                        break;
                    }
                    stack.Push(new JSONClass());
                    if (jSONNode != null)
                    {
                        text2 = text2.Trim();
                        if (jSONNode is JSONArray)
                        {
                            jSONNode.Add(stack.Peek());
                        }
                        else if (text2 != string.Empty)
                        {
                            jSONNode.Add(text2, stack.Peek());
                        }
                    }
                    text2    = string.Empty;
                    text     = string.Empty;
                    jSONNode = stack.Peek();
                    break;

                case '[':
                    if (flag)
                    {
                        text += aJSON[i];
                        break;
                    }
                    stack.Push(new JSONArray());
                    if (jSONNode != null)
                    {
                        text2 = text2.Trim();
                        if (jSONNode is JSONArray)
                        {
                            jSONNode.Add(stack.Peek());
                        }
                        else if (text2 != string.Empty)
                        {
                            jSONNode.Add(text2, stack.Peek());
                        }
                    }
                    text2    = string.Empty;
                    text     = string.Empty;
                    jSONNode = stack.Peek();
                    break;

                case ']':
                case '}':
                    if (flag)
                    {
                        text += aJSON[i];
                        break;
                    }
                    if (stack.Count == 0)
                    {
                        throw new Exception("JSON Parse: Too many closing brackets");
                    }
                    stack.Pop();
                    if (text != string.Empty)
                    {
                        text2 = text2.Trim();
                        if (jSONNode is JSONArray)
                        {
                            jSONNode.Add(text);
                        }
                        else if (text2 != string.Empty)
                        {
                            jSONNode.Add(text2, text);
                        }
                    }
                    text2 = string.Empty;
                    text  = string.Empty;
                    if (stack.Count > 0)
                    {
                        jSONNode = stack.Peek();
                    }
                    break;

                case ':':
                    if (flag)
                    {
                        text += aJSON[i];
                        break;
                    }
                    text2 = text;
                    text  = string.Empty;
                    break;

                case '"':
                    flag = ((byte)((flag ? 1 : 0) ^ 1) != 0);
                    break;

                case ',':
                    if (flag)
                    {
                        text += aJSON[i];
                        break;
                    }
                    if (text != string.Empty)
                    {
                        if (jSONNode is JSONArray)
                        {
                            jSONNode.Add(text);
                        }
                        else if (text2 != string.Empty)
                        {
                            jSONNode.Add(text2, text);
                        }
                    }
                    text2 = string.Empty;
                    text  = string.Empty;
                    break;

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

                case '\\':
                    i++;
                    if (flag)
                    {
                        char c = aJSON[i];
                        switch (c)
                        {
                        case 't':
                            text += '\t';
                            break;

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

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

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

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

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

                        default:
                            text += c;
                            break;
                        }
                    }
                    break;

                default:
                    text += aJSON[i];
                    break;

                case '\n':
                case '\r':
                    break;
                }
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jSONNode);
        }
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> jSONNodes = new Stack <JSONNode>();
            JSONNode         jSONNode  = null;
            int    num   = 0;
            string empty = string.Empty;
            string str   = string.Empty;
            bool   flag  = false;

            while (num < aJSON.Length)
            {
                char chr = aJSON[num];
                switch (chr)
                {
                case '\t':
                {
Label0:
                    if (flag)
                    {
                        empty = string.Concat(empty, aJSON[num]);
                    }
                    break;
                }

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

                default:
                {
                    switch (chr)
                    {
                    case '[':
                    {
                        if (!flag)
                        {
                            jSONNodes.Push(new JSONArray());
                            if (jSONNode != null)
                            {
                                str = str.Trim();
                                if (jSONNode is JSONArray)
                                {
                                    jSONNode.Add(jSONNodes.Peek());
                                }
                                else if (str != string.Empty)
                                {
                                    jSONNode.Add(str, jSONNodes.Peek());
                                }
                            }
                            str      = string.Empty;
                            empty    = string.Empty;
                            jSONNode = jSONNodes.Peek();
                        }
                        else
                        {
                            empty = string.Concat(empty, aJSON[num]);
                        }
                        break;
                    }

                    case '\\':
                    {
                        num++;
                        if (flag)
                        {
                            char chr1 = aJSON[num];
                            switch (chr1)
                            {
                            case 'r':
                            {
                                empty = string.Concat(empty, '\r');
                                break;
                            }

                            case 't':
                            {
                                empty = string.Concat(empty, '\t');
                                break;
                            }

                            case 'u':
                            {
                                string str1 = aJSON.Substring(num + 1, 4);
                                empty = string.Concat(empty, (char)int.Parse(str1, NumberStyles.AllowHexSpecifier));
                                num  += 4;
                                break;
                            }

                            default:
                            {
                                if (chr1 == 'b')
                                {
                                    empty = string.Concat(empty, '\b');
                                    break;
                                }
                                else if (chr1 == 'f')
                                {
                                    empty = string.Concat(empty, '\f');
                                    break;
                                }
                                else if (chr1 == 'n')
                                {
                                    empty = string.Concat(empty, '\n');
                                    break;
                                }
                                else
                                {
                                    empty = string.Concat(empty, chr1);
                                    break;
                                }
                            }
                            }
                        }
                        break;
                    }

                    case ']':
                    {
Label1:
                        if (!flag)
                        {
                            if (jSONNodes.Count == 0)
                            {
                                throw new Exception("JSON Parse: Too many closing brackets");
                            }
                            jSONNodes.Pop();
                            if (empty != string.Empty)
                            {
                                str = str.Trim();
                                if (jSONNode is JSONArray)
                                {
                                    jSONNode.Add(empty);
                                }
                                else if (str != string.Empty)
                                {
                                    jSONNode.Add(str, empty);
                                }
                            }
                            str   = string.Empty;
                            empty = string.Empty;
                            if (jSONNodes.Count > 0)
                            {
                                jSONNode = jSONNodes.Peek();
                            }
                        }
                        else
                        {
                            empty = string.Concat(empty, aJSON[num]);
                        }
                        break;
                    }

                    default:
                    {
                        switch (chr)
                        {
                        case ' ':
                        {
                            goto Label0;
                        }

                        case '\"':
                        {
                            flag ^= 1;
                            break;
                        }

                        default:
                        {
                            switch (chr)
                            {
                            case '{':
                            {
                                if (!flag)
                                {
                                    jSONNodes.Push(new JSONClass());
                                    if (jSONNode != null)
                                    {
                                        str = str.Trim();
                                        if (jSONNode is JSONArray)
                                        {
                                            jSONNode.Add(jSONNodes.Peek());
                                        }
                                        else if (str != string.Empty)
                                        {
                                            jSONNode.Add(str, jSONNodes.Peek());
                                        }
                                    }
                                    str      = string.Empty;
                                    empty    = string.Empty;
                                    jSONNode = jSONNodes.Peek();
                                }
                                else
                                {
                                    empty = string.Concat(empty, aJSON[num]);
                                }
                                break;
                            }

                            case '}':
                            {
                                goto Label1;
                            }

                            default:
                            {
                                if (chr == ',')
                                {
                                    if (!flag)
                                    {
                                        if (empty != string.Empty)
                                        {
                                            if (jSONNode is JSONArray)
                                            {
                                                jSONNode.Add(empty);
                                            }
                                            else if (str != string.Empty)
                                            {
                                                jSONNode.Add(str, empty);
                                            }
                                        }
                                        str   = string.Empty;
                                        empty = string.Empty;
                                    }
                                    else
                                    {
                                        empty = string.Concat(empty, aJSON[num]);
                                    }
                                }
                                else if (chr != ':')
                                {
                                    empty = string.Concat(empty, aJSON[num]);
                                }
                                else if (!flag)
                                {
                                    str   = empty;
                                    empty = string.Empty;
                                }
                                else
                                {
                                    empty = string.Concat(empty, aJSON[num]);
                                }
                                break;
                            }
                            }
                            break;
                        }
                        }
                        break;
                    }
                    }
                    break;
                }
                }
                num++;
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jSONNode);
        }
Пример #10
0
        public static JSONNode Parse(String aJSON)
        {
            Stack <JSONNode> stack    = new Stack <JSONNode>();
            JSONNode         jsonnode = (JSONNode)null;
            Int32            i        = 0;
            String           text     = String.Empty;
            String           text2    = String.Empty;
            Boolean          flag     = false;

            while (i < aJSON.Length)
            {
                Char c = aJSON[i];
                switch (c)
                {
                case '\t':
                    goto IL_333;

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

                case '\v':
                case '\f':
IL_46:
                    switch (c)
                    {
                    case ' ':
                        goto IL_333;

                    case '!':
IL_5C:
                        switch (c)
                        {
                        case '[':
                            if (flag)
                            {
                                text += aJSON[i];
                                goto IL_467;
                            }
                            stack.Push(new JSONArray());
                            if (jsonnode != null)
                            {
                                text2 = text2.Trim();
                                if (jsonnode is JSONArray)
                                {
                                    jsonnode.Add(stack.Peek());
                                }
                                else if (text2 != String.Empty)
                                {
                                    jsonnode.Add(text2, stack.Peek());
                                }
                            }
                            text2    = String.Empty;
                            text     = String.Empty;
                            jsonnode = stack.Peek();
                            goto IL_467;

                        case '\\':
                            i++;
                            if (flag)
                            {
                                Char c2 = aJSON[i];
                                Char c3 = c2;
                                switch (c3)
                                {
                                case 'n':
                                    text += '\n';
                                    break;

                                case 'o':
                                case 'p':
                                case 'q':
                                case 's':
IL_394:
                                    if (c3 != 'b')
                                    {
                                        if (c3 != 'f')
                                        {
                                            text += c2;
                                        }
                                        else
                                        {
                                            text += '\f';
                                        }
                                    }
                                    else
                                    {
                                        text += '\b';
                                    }
                                    break;

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

                                case 't':
                                    text += '\t';
                                    break;

                                case 'u':
                                {
                                    String s = aJSON.Substring(i + 1, 4);
                                    text += (Char)Int32.Parse(s, NumberStyles.AllowHexSpecifier);
                                    i    += 4;
                                    break;
                                }

                                default:
                                    goto IL_394;
                                }
                            }
                            goto IL_467;

                        case ']':
                            break;

                        default:
                            switch (c)
                            {
                            case '{':
                                if (flag)
                                {
                                    text += aJSON[i];
                                    goto IL_467;
                                }
                                stack.Push(new JSONClass());
                                if (jsonnode != null)
                                {
                                    text2 = text2.Trim();
                                    if (jsonnode is JSONArray)
                                    {
                                        jsonnode.Add(stack.Peek());
                                    }
                                    else if (text2 != String.Empty)
                                    {
                                        jsonnode.Add(text2, stack.Peek());
                                    }
                                }
                                text2    = String.Empty;
                                text     = String.Empty;
                                jsonnode = stack.Peek();
                                goto IL_467;

                            case '|':
IL_88:
                                if (c != ',')
                                {
                                    if (c != ':')
                                    {
                                        text += aJSON[i];
                                        goto IL_467;
                                    }
                                    if (flag)
                                    {
                                        text += aJSON[i];
                                        goto IL_467;
                                    }
                                    text2 = text;
                                    text  = String.Empty;
                                    goto IL_467;
                                }
                                else
                                {
                                    if (flag)
                                    {
                                        text += aJSON[i];
                                        goto IL_467;
                                    }
                                    if (text != String.Empty)
                                    {
                                        if (jsonnode is JSONArray)
                                        {
                                            jsonnode.Add(text);
                                        }
                                        else if (text2 != String.Empty)
                                        {
                                            jsonnode.Add(text2, text);
                                        }
                                    }
                                    text2 = String.Empty;
                                    text  = String.Empty;
                                    goto IL_467;
                                }

                            case '}':
                                break;

                            default:
                                goto IL_88;
                            }
                            break;
                        }
                        if (flag)
                        {
                            text += aJSON[i];
                        }
                        else
                        {
                            if (stack.Count == 0)
                            {
                                throw new Exception("JSON Parse: Too many closing brackets");
                            }
                            stack.Pop();
                            if (text != String.Empty)
                            {
                                text2 = text2.Trim();
                                if (jsonnode is JSONArray)
                                {
                                    jsonnode.Add(text);
                                }
                                else if (text2 != String.Empty)
                                {
                                    jsonnode.Add(text2, text);
                                }
                            }
                            text2 = String.Empty;
                            text  = String.Empty;
                            if (stack.Count > 0)
                            {
                                jsonnode = stack.Peek();
                            }
                        }
                        break;

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

                    default:
                        goto IL_5C;
                    }
                    break;

                default:
                    goto IL_46;
                }
IL_467:
                i++;
                continue;
IL_333:
                if (flag)
                {
                    text += aJSON[i];
                }
                goto IL_467;
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jsonnode);
        }
Пример #11
0
        public static JSONNode Parse(string aJSON)
        {
            var      stack         = new Stack <JSONNode>();
            JSONNode ctx           = null;
            var      i             = 0;
            var      Token         = new StringBuilder();
            var      TokenName     = new StringBuilder();
            var      QuoteMode     = false;
            var      TokenIsString = false;

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

                    stack.Push(new JSONClass());
                    if (ctx != null)
                    {
                        var tmpName = TokenName.ToString().Trim();
                        if (ctx is JSONArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (tmpName != "")
                        {
                            ctx.Add(tmpName, stack.Peek());
                        }
                    }

                    TokenName.Length = 0;
                    Token.Length     = 0;
                    ctx = stack.Peek();
                    break;

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

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

                    TokenName.Length = 0;
                    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)
                    {
                        AddElement(ctx, Token.ToString(), TokenName.ToString().Trim(), TokenIsString);
                        TokenIsString = false;
                    }

                    TokenName.Length = 0;
                    Token.Length     = 0;
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }

                    break;

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

                    TokenName.Length = 0;
                    TokenName.Append(Token);
                    Token.Length  = 0;
                    TokenIsString = false;
                    break;

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

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

                    if (Token.Length > 0)
                    {
                        AddElement(ctx, Token.ToString(), TokenName.ToString(), TokenIsString);
                        TokenIsString = false;
                    }

                    TokenName.Length = 0;
                    Token.Length     = 0;
                    TokenIsString    = false;
                    break;

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

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

                    break;

                case '\\':
                    ++i;
                    if (QuoteMode)
                    {
                        var 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':
                        {
                            var s = aJSON.Substring(i + 1, 4);
                            Token.Append((char)int.Parse(
                                             s,
                                             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);
        }
Пример #12
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack    = new Stack <JSONNode>();
            JSONNode         jsonnode = null;
            int    i     = 0;
            string text  = string.Empty;
            string text2 = string.Empty;
            bool   flag  = false;

            while (i < aJSON.Length)
            {
                char c = aJSON[i];
                switch (c)
                {
                case '\t':
                    goto IL_333;

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

                default:
                    switch (c)
                    {
                    case '[':
                        if (flag)
                        {
                            text += aJSON[i];
                            goto IL_45C;
                        }
                        stack.Push(new JSONArray());
                        if (jsonnode != null)
                        {
                            text2 = text2.Trim();
                            if (jsonnode is JSONArray)
                            {
                                jsonnode.Add(stack.Peek());
                            }
                            else if (text2 != string.Empty)
                            {
                                jsonnode.Add(text2, stack.Peek());
                            }
                        }
                        text2    = string.Empty;
                        text     = string.Empty;
                        jsonnode = stack.Peek();
                        goto IL_45C;

                    case '\\':
                        i++;
                        if (flag)
                        {
                            char c2 = aJSON[i];
                            switch (c2)
                            {
                            case 'r':
                                text += '\r';
                                break;

                            default:
                                if (c2 != 'b')
                                {
                                    if (c2 != 'f')
                                    {
                                        if (c2 != 'n')
                                        {
                                            text += c2;
                                        }
                                        else
                                        {
                                            text += '\n';
                                        }
                                    }
                                    else
                                    {
                                        text += '\f';
                                    }
                                }
                                else
                                {
                                    text += '\b';
                                }
                                break;

                            case 't':
                                text += '\t';
                                break;

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

                    case ']':
                        break;

                    default:
                        switch (c)
                        {
                        case ' ':
                            goto IL_333;

                        default:
                            switch (c)
                            {
                            case '{':
                                if (flag)
                                {
                                    text += aJSON[i];
                                    goto IL_45C;
                                }
                                stack.Push(new JSONClass());
                                if (jsonnode != null)
                                {
                                    text2 = text2.Trim();
                                    if (jsonnode is JSONArray)
                                    {
                                        jsonnode.Add(stack.Peek());
                                    }
                                    else if (text2 != string.Empty)
                                    {
                                        jsonnode.Add(text2, stack.Peek());
                                    }
                                }
                                text2    = string.Empty;
                                text     = string.Empty;
                                jsonnode = stack.Peek();
                                goto IL_45C;

                            default:
                                if (c != ',')
                                {
                                    if (c != ':')
                                    {
                                        text += aJSON[i];
                                        goto IL_45C;
                                    }
                                    if (flag)
                                    {
                                        text += aJSON[i];
                                        goto IL_45C;
                                    }
                                    text2 = text;
                                    text  = string.Empty;
                                    goto IL_45C;
                                }
                                else
                                {
                                    if (flag)
                                    {
                                        text += aJSON[i];
                                        goto IL_45C;
                                    }
                                    if (text != string.Empty)
                                    {
                                        if (jsonnode is JSONArray)
                                        {
                                            jsonnode.Add(text);
                                        }
                                        else if (text2 != string.Empty)
                                        {
                                            jsonnode.Add(text2, text);
                                        }
                                    }
                                    text2 = string.Empty;
                                    text  = string.Empty;
                                    goto IL_45C;
                                }
                                break;

                            case '}':
                                break;
                            }
                            break;

                        case '"':
                            flag ^= true;
                            goto IL_45C;
                        }
                        break;
                    }
                    if (flag)
                    {
                        text += aJSON[i];
                    }
                    else
                    {
                        if (stack.Count == 0)
                        {
                            throw new Exception("JSON Parse: Too many closing brackets");
                        }
                        stack.Pop();
                        if (text != string.Empty)
                        {
                            text2 = text2.Trim();
                            if (jsonnode is JSONArray)
                            {
                                jsonnode.Add(text);
                            }
                            else if (text2 != string.Empty)
                            {
                                jsonnode.Add(text2, text);
                            }
                        }
                        text2 = string.Empty;
                        text  = string.Empty;
                        if (stack.Count > 0)
                        {
                            jsonnode = stack.Peek();
                        }
                    }
                    break;
                }
IL_45C:
                i++;
                continue;
IL_333:
                if (flag)
                {
                    text += aJSON[i];
                }
                goto IL_45C;
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jsonnode);
        }
Пример #13
0
        public static JSONNode Parse(string aJSON)
        {
            var      stack         = new Stack <JSONNode>();
            JSONNode ctx           = null;
            var      i             = 0;
            var      token         = "";
            var      tokenName     = "";
            var      quoteMode     = false;
            var      tokenIsString = 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);
                         */
                        AddElement(ctx, token, tokenName, tokenIsString);
                        tokenIsString = false;
                    }
                    tokenName = "";
                    token     = "";
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (quoteMode)
                    {
                        token += aJSON[i];
                        break;
                    }
                    tokenName     = token;
                    token         = "";
                    tokenIsString = false;
                    break;

                case '"':
                    quoteMode    ^= true;
                    tokenIsString = true;
                    break;

                case ',':
                    if (quoteMode)
                    {
                        token += aJSON[i];
                        break;
                    }
                    if (token != "")
                    {
                        AddElement(ctx, token, tokenName, tokenIsString);
                    }
                    tokenName     = "";
                    token         = "";
                    tokenIsString = false;
                    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);
        }
Пример #14
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 || TokenIsQuoted)
                    {
                        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();
                    Token.Length  = 0;
                    TokenIsQuoted = false;
                    break;

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

                case ',':
                    if (QuoteMode)
                    {
                        Token.Append(aJSON[i]);
                        break;
                    }
                    if (Token.Length > 0 || TokenIsQuoted)
                    {
                        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);
        }
Пример #15
0
	public void OnButtonDrawSingleCard(){
		int random = UnityEngine.Random.Range (1, numberOfCounselors + numberOfGenerals);
		bool isCounselors = (random <= numberOfCounselors);
		int result = (isCounselors) ? random : random - numberOfCounselors + 1000;

		//Debug.Log ("Random Number: "+random);

		//Debug.Log ("Result Number: "+ result);

		Storage s = new Storage(){productId= result, type =2, quantity =1}; //TODO: Personnel number instead of 0.

		json = new JSONClass ();
		if (isCounselors) {
			json["data"].Add ("userId",new JSONData(game.login.id));
			json["data"].Add ("type" , new JSONData(result));
			json["data"].Add ("level", new JSONData(1));
		} else {
			json.Add ("data", (JSONNode)s.toJSON ());
			json["data"].Add ("userId",new JSONData (game.login.id));
		}
		if (isCounselors) {
			json ["action"] = "NEW";
			json ["table"] = (isCounselors) ? "counselors" : "storage";
			Debug.Log (json.ToString ());
			wsc.Send (json.ToString ());
		}
	}
Пример #16
0
		static void AddElement (JSONNode ctx, string token, string tokenName, bool tokenIsString)
		{
			if (tokenIsString) {
				if (ctx is JSONArray)
					ctx.Add (token);
				else
					ctx.Add (tokenName, token); // assume dictionary/object
			} else {
				JSONData number = Numberize (token);
				if (ctx is JSONArray)
					ctx.Add (number);
				else
					ctx.Add (tokenName, number);
				
			}
		}
Пример #17
0
        public static JSONNode Parse(string aJSON)
        {
            Stack <JSONNode> stack    = new Stack <JSONNode>();
            JSONNode         jSONNode = null;
            int    i     = 0;
            string text  = string.Empty;
            string text2 = string.Empty;
            bool   flag  = false;

            while (i < aJSON.get_Length())
            {
                char c = aJSON.get_Chars(i);
                switch (c)
                {
                case '\t':
                    goto IL_333;

                case '\n':
                case '\r':
                    goto IL_467;

                case '\v':
                case '\f':
IL_46:
                    switch (c)
                    {
                    case ' ':
                        goto IL_333;

                    case '!':
IL_5C:
                        switch (c)
                        {
                        case '[':
                            if (flag)
                            {
                                text += aJSON.get_Chars(i);
                                goto IL_467;
                            }
                            stack.Push(new JSONArray());
                            if (jSONNode != null)
                            {
                                text2 = text2.Trim();
                                if (jSONNode is JSONArray)
                                {
                                    jSONNode.Add(stack.Peek());
                                }
                                else if (text2 != string.Empty)
                                {
                                    jSONNode.Add(text2, stack.Peek());
                                }
                            }
                            text2    = string.Empty;
                            text     = string.Empty;
                            jSONNode = stack.Peek();
                            goto IL_467;

                        case '\\':
                            i++;
                            if (flag)
                            {
                                char c2 = aJSON.get_Chars(i);
                                char c3 = c2;
                                switch (c3)
                                {
                                case 'n':
                                    text += '\n';
                                    goto IL_44A;

                                case 'o':
                                case 'p':
                                case 'q':
                                case 's':
IL_394:
                                    if (c3 == 'b')
                                    {
                                        text += '\b';
                                        goto IL_44A;
                                    }
                                    if (c3 != 'f')
                                    {
                                        text += c2;
                                        goto IL_44A;
                                    }
                                    text += '\f';
                                    goto IL_44A;

                                case 'r':
                                    text += '\r';
                                    goto IL_44A;

                                case 't':
                                    text += '\t';
                                    goto IL_44A;

                                case 'u':
                                {
                                    string text3 = aJSON.Substring(i + 1, 4);
                                    text += (char)int.Parse(text3, 512);
                                    i    += 4;
                                    goto IL_44A;
                                }
                                }
                                goto IL_394;
                            }
IL_44A:
                            goto IL_467;

                        case ']':
                            break;

                        default:
                            switch (c)
                            {
                            case '{':
                                if (flag)
                                {
                                    text += aJSON.get_Chars(i);
                                    goto IL_467;
                                }
                                stack.Push(new JSONClass());
                                if (jSONNode != null)
                                {
                                    text2 = text2.Trim();
                                    if (jSONNode is JSONArray)
                                    {
                                        jSONNode.Add(stack.Peek());
                                    }
                                    else if (text2 != string.Empty)
                                    {
                                        jSONNode.Add(text2, stack.Peek());
                                    }
                                }
                                text2    = string.Empty;
                                text     = string.Empty;
                                jSONNode = stack.Peek();
                                goto IL_467;

                            case '|':
IL_88:
                                if (c != ',')
                                {
                                    if (c != ':')
                                    {
                                        text += aJSON.get_Chars(i);
                                        goto IL_467;
                                    }
                                    if (flag)
                                    {
                                        text += aJSON.get_Chars(i);
                                        goto IL_467;
                                    }
                                    text2 = text;
                                    text  = string.Empty;
                                    goto IL_467;
                                }
                                else
                                {
                                    if (flag)
                                    {
                                        text += aJSON.get_Chars(i);
                                        goto IL_467;
                                    }
                                    if (text != string.Empty)
                                    {
                                        if (jSONNode is JSONArray)
                                        {
                                            jSONNode.Add(text);
                                        }
                                        else if (text2 != string.Empty)
                                        {
                                            jSONNode.Add(text2, text);
                                        }
                                    }
                                    text2 = string.Empty;
                                    text  = string.Empty;
                                    goto IL_467;
                                }
                                break;

                            case '}':
                                goto IL_1C5;
                            }
                            goto IL_88;
                        }
IL_1C5:
                        if (flag)
                        {
                            text += aJSON.get_Chars(i);
                            goto IL_467;
                        }
                        if (stack.get_Count() == 0)
                        {
                            throw new Exception("JSON Parse: Too many closing brackets");
                        }
                        stack.Pop();
                        if (text != string.Empty)
                        {
                            text2 = text2.Trim();
                            if (jSONNode is JSONArray)
                            {
                                jSONNode.Add(text);
                            }
                            else if (text2 != string.Empty)
                            {
                                jSONNode.Add(text2, text);
                            }
                        }
                        text2 = string.Empty;
                        text  = string.Empty;
                        if (stack.get_Count() > 0)
                        {
                            jSONNode = stack.Peek();
                        }
                        goto IL_467;

                    case '"':
                        flag ^= true;
                        goto IL_467;
                    }
                    goto IL_5C;
                }
                goto IL_46;
IL_467:
                i++;
                continue;
IL_333:
                if (flag)
                {
                    text += aJSON.get_Chars(i);
                }
                goto IL_467;
            }
            if (flag)
            {
                throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
            }
            return(jSONNode);
        }