Beispiel #1
0
        private object GetKeywordFromString(MyStringReader jsonString, char ch)
        {
            switch (ch)
            {
            case 't':
                if (CheckArray(jsonString.ReadChars(3), TRUE_ARRAY))
                {
                    return(true);
                }
                goto default;

            case 'f':
                if (CheckArray(jsonString.ReadChars(4), FALSE_ARRAY))
                {
                    return(false);
                }
                goto default;

            case 'n':
                if (CheckArray(jsonString.ReadChars(3), NULL_ARRAY))
                {
                    return(null);
                }
                goto default;

            default:
                throw new Exception("Invalid JSON document.");
            }
        }
Beispiel #2
0
        private string GetStringFromString(MyStringReader jsonString)
        {
            char          ch;
            StringBuilder sb            = new StringBuilder();
            bool          backslashMode = false;

            while (true)
            {
                ch = jsonString.ReadChar();
                if (backslashMode)
                {
                    switch (ch)
                    {
                    case 'n': sb [sb.Length - 1] = '\n'; break;

                    case 'r': sb [sb.Length - 1] = '\r'; break;

                    case 't': sb [sb.Length - 1] = '\t'; break;

                    case '\\': sb [sb.Length - 1] = '\\'; break;

                    case '"': sb [sb.Length - 1] = '"'; break;

                    case '/': sb [sb.Length - 1] = '/'; break;

                    case 'b': sb [sb.Length - 1] = '\b'; break;

                    case 'f': sb [sb.Length - 1] = '\f'; break;

                    case 'u':
                        sb.Remove(sb.Length - 1, 1);
                        sb.Append(ToNumberFromHexa(jsonString.ReadChars(2)));
                        sb.Append(ToNumberFromHexa(jsonString.ReadChars(2)));
                        break;

                    default: throw new Exception();
                    }
                    backslashMode = false;
                }
                else if (ch == '"')
                {
                    break;
                }
                else
                {
                    sb.Append(ch);
                    if (ch == '\\')
                    {
                        backslashMode = true;
                    }
                }
            }
            return(sb.ToString());
        }