コード例 #1
0
ファイル: JsonObjectReader.cs プロジェクト: rhemm23/bolt
        private void ReadKeyValuePair(JsonStringReader keyReader, JsonReaderDirector director, JsonObject result)
        {
            JsonString key = (JsonString)keyReader.Read();

            this._json.ReadWhitespace();

            // Assure colon between key/value
            if (this._json.Read() != 58)
            {
                throw new JsonFormatException("Expected ':' after object key");
            }

            result.Add(key.Value, director.ReadValue());
        }
コード例 #2
0
        public IJsonValue ReadValue()
        {
            JsonReader reader;

            this._json.ReadWhitespace();
            switch (this._json.Peek())
            {
            case int digit when(digit >= 48 && digit <= 57):
            case 45:
                reader = new JsonNumberReader(this._json);

                break;

            case 34:
                reader = new JsonStringReader(this._json);
                break;

            case 116:
            case 102:
                reader = new JsonBooleanReader(this._json);
                break;

            case 110:
                reader = new JsonNullReader(this._json);
                break;

            case 91:
                reader = new JsonArrayReader(this._json);
                break;

            case 123:
                reader = new JsonObjectReader(this._json);
                break;

            default:
                throw new JsonFormatException("Expected to read a value");
            }

            // Read value, then whitespace
            IJsonValue val = reader.Read();

            this._json.ReadWhitespace();
            return(val);
        }
コード例 #3
0
ファイル: JsonObjectReader.cs プロジェクト: rhemm23/bolt
        public override IJsonValue Read()
        {
            JsonReaderDirector director     = new JsonReaderDirector(this._json);
            JsonStringReader   stringReader = new JsonStringReader(this._json);
            JsonObject         result       = new JsonObject();
            States             state        = States.Start;

            while (state != States.End)
            {
                switch (state)
                {
                case States.Start:
                    switch (this._json.Peek())
                    {
                    case 123:
                        this._json.Read();
                        state = States.ReadOpeningBracket;
                        break;

                    default:
                        throw new JsonFormatException("Expected '{' to start an object");
                    }
                    break;

                case States.ReadOpeningBracket:
                    this._json.ReadWhitespace();
                    switch (this._json.Peek())
                    {
                    case 125:
                        this._json.Read();
                        state = States.End;
                        break;

                    default:
                        ReadKeyValuePair(stringReader, director, result);
                        state = States.ReadKeyValuePair;
                        break;
                    }
                    break;

                case States.ReadKeyValuePair:
                    switch (this._json.Peek())
                    {
                    case 125:
                        this._json.Read();
                        state = States.End;
                        break;

                    case 44:
                        this._json.Read();
                        this._json.ReadWhitespace();
                        ReadKeyValuePair(stringReader, director, result);
                        break;

                    default:
                        throw new JsonFormatException("Expected a ',' or '}' after key value pair in object");
                    }
                    break;

                case States.End:
                    break;
                }
            }
            return(result);
        }