Пример #1
0
        /// <summary>
        /// Writes an array value.
        /// </summary>
        public void WriteArrayValue(string value, bool useQuotes = false, bool escape = true)
        {
            if (_statusStack.Count == 0)
            {
                throw new Exception("Cannot write array at this point.");
            }
            else
            {
                var status = _statusStack.Peek();
                if (status != Status.ArrayOpenWritten &&
                    status != Status.ArrayValueWritten)
                {
                    throw new Exception("Cannot write array at this point.");
                }

                if (status == Status.ArrayValueWritten)
                {
                    _writer.Write(",");
                }
            }

            if (useQuotes)
            {
                _writer.Write('"');
            }
            if (escape)
            {
                value = JsonTools.Escape(value);
            }
            _writer.Write(value);
            if (useQuotes)
            {
                _writer.Write('"');
            }
            _statusStack.Push(Status.ArrayValueWritten);
        }