Example #1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		public JSONWriter(TextWriter writer) {
			this.writer = writer;
			this.location = JSONLocation.Normal;
			this.lastLocations = new Stack();
			this.index = 0;
			this.lastIndex = 0;
		}
Example #2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="reader"></param>
		public JSONReader(TextReader reader) {
			this.reader = reader;
			this.val = null;
			this.token = JSONToken.Null;
			this.location = JSONLocation.Normal;
			this.lastLocations = new Stack();
			this.needProp = false;
		}
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="writer"></param>
 public JSONWriter(TextWriter writer)
 {
     this.writer        = writer;
     this.location      = JSONLocation.Normal;
     this.lastLocations = new Stack();
     this.index         = 0;
     this.lastIndex     = 0;
 }
Example #4
0
		/// <summary>
		/// 
		/// </summary>
		public void WriteStartArray() {
			this.WriteDelim();
			this.writer.Write('[');
			this.lastLocations.Push(this.location);
			this.lastIndex = this.index;
			this.location = JSONLocation.InArray;
			this.index = 0;
		}
Example #5
0
		/// <summary>
		/// 
		/// </summary>
		public void WriteStartObject() {
			this.WriteDelim();
			this.writer.Write('{');
			this.lastLocations.Push(this.location);
			this.lastIndex = this.index;
			this.location = JSONLocation.InObject;
			this.index = 0;
		}
Example #6
0
 /// <summary>
 ///
 /// </summary>
 public void WriteStartArray()
 {
     this.WriteDelim();
     this.writer.Write('[');
     this.lastLocations.Push(this.location);
     this.lastIndex = this.index;
     this.location  = JSONLocation.InArray;
     this.index     = 0;
 }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 public void WriteStartObject()
 {
     this.WriteDelim();
     this.writer.Write('{');
     this.lastLocations.Push(this.location);
     this.lastIndex = this.index;
     this.location  = JSONLocation.InObject;
     this.index     = 0;
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 public JSONReader(TextReader reader)
 {
     this.reader        = reader;
     this.val           = null;
     this.token         = JSONToken.Null;
     this.location      = JSONLocation.Normal;
     this.lastLocations = new Stack();
     this.needProp      = false;
 }
Example #9
0
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public bool Read() {
			int chr = this.reader.Read();

			if (chr != -1) {
				switch ((char) chr) {
					case '[':
						this.lastLocations.Push(this.location);
						this.location = JSONLocation.InArray;
						this.token = JSONToken.StartArray;
						this.val = null;
						this.ReadAway();
						return true;

					case ']':
						this.location = (JSONLocation) this.lastLocations.Pop();
						this.token = JSONToken.EndArray;
						this.val = null;
						this.ReadAway();

						if (this.location == JSONLocation.InObject)
							this.needProp = true;

						return true;

					case '{':
						this.lastLocations.Push(this.location);
						this.location = JSONLocation.InObject;
						this.needProp = true;
						this.token = JSONToken.StartObject;
						this.val = null;
						this.ReadAway();
						return true;

					case '}':
						this.location = (JSONLocation) this.lastLocations.Pop();
						this.token = JSONToken.EndObject;
						this.val = null;
						this.ReadAway();

						if (this.location == JSONLocation.InObject)
							this.needProp = true;

						return true;

					// String
					case '"':
					case '\'':
						return this.ReadString((char) chr);

					// Null
					case 'n':
						return this.ReadNull();

					// Bool
					case 't':
					case 'f':
						return this.ReadBool((char) chr);

					default:
						// Is number
						if (Char.IsNumber((char) chr) || (char) chr == '-' || (char) chr == '.')
							return this.ReadNumber((char) chr);

						return true;
				}
			}

			return false;
		}
Example #10
0
 /// <summary>
 ///
 /// </summary>
 public void WriteEndArray()
 {
     this.writer.Write(']');
     this.location = (JSONLocation)lastLocations.Pop();
     this.index    = this.lastIndex;
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 public void WriteEndObject()
 {
     this.writer.Write('}');
     this.location = (JSONLocation)lastLocations.Pop();
     this.index    = this.lastIndex;
 }
Example #12
0
 /// <summary>
 /// 
 /// </summary>
 public void WriteEndObject()
 {
     this.writer.Write('}');
     this.location = (JSONLocation)lastLocations.Pop();
     this.index = this.lastIndex;
 }
Example #13
0
 /// <summary>
 /// 
 /// </summary>
 public void WriteEndArray()
 {
     this.writer.Write(']');
     this.location = (JSONLocation)lastLocations.Pop();
     this.index = this.lastIndex;
 }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
            int chr = this.reader.Read();

            if (chr != -1)
            {
                switch ((char)chr)
                {
                case '[':
                    this.lastLocations.Push(this.location);
                    this.location = JSONLocation.InArray;
                    this.token    = JSONToken.StartArray;
                    this.val      = null;
                    this.ReadAway();
                    return(true);

                case ']':
                    this.location = (JSONLocation)this.lastLocations.Pop();
                    this.token    = JSONToken.EndArray;
                    this.val      = null;
                    this.ReadAway();

                    if (this.location == JSONLocation.InObject)
                    {
                        this.needProp = true;
                    }

                    return(true);

                case '{':
                    this.lastLocations.Push(this.location);
                    this.location = JSONLocation.InObject;
                    this.needProp = true;
                    this.token    = JSONToken.StartObject;
                    this.val      = null;
                    this.ReadAway();
                    return(true);

                case '}':
                    this.location = (JSONLocation)this.lastLocations.Pop();
                    this.token    = JSONToken.EndObject;
                    this.val      = null;
                    this.ReadAway();

                    if (this.location == JSONLocation.InObject)
                    {
                        this.needProp = true;
                    }

                    return(true);

                // String
                case '"':
                case '\'':
                    return(this.ReadString((char)chr));

                // Null
                case 'n':
                    return(this.ReadNull());

                // Bool
                case 't':
                case 'f':
                    return(this.ReadBool((char)chr));

                default:
                    // Is number
                    if (Char.IsNumber((char)chr) || (char)chr == '-' || (char)chr == '.')
                    {
                        return(this.ReadNumber((char)chr));
                    }

                    return(true);
                }
            }

            return(false);
        }