Exemple #1
0
        /// <summary>
        /// Gets a string of characters representing the underlying
        /// class and formatted like a json array.
        /// </summary>
        /// <returns>
        /// A string representation of the <see cref="JsonTable"/> class
        /// that represents a json array.
        /// </returns>
        public string AsJson()
        {
            if (columns_.Length == 0)
            {
                return("{\"columns\":[], \"rows\":[[]]}");
            }

            const string kColumnNamesMemberName = "columns";
            const string kDataMemberName        = "rows";

            JsonStringBuilder builder = new JsonStringBuilder()
                                        .WriteBeginObject()
                                        .WriteMemberName(kColumnNamesMemberName)
                                        .WriteStringArray(columns_)
                                        .WriteMemberName(kDataMemberName)
                                        .WriteBeginArray();

            if (rows_.Count == 0)
            {
                builder.WriteBeginArray().WriteEndArray();
            }
            else
            {
                for (int i = 0, j = rows_.Count; i < j; i++)
                {
                    builder.WriteUnquotedString(rows_[i].AsJson());
                }
            }
            return(builder.WriteEndArray().WriteEndObject().ToString());
        }
Exemple #2
0
        /// <summary>
        /// Gets the json string representation of the <see cref="IJsonToken{T}"/>
        /// class.
        /// </summary>
        /// <returns>
        /// The json string representation of the <see cref="IJsonToken{T}"/>
        /// class.
        /// </returns>
        public string AsJson()
        {
            JsonStringBuilder builder = new JsonStringBuilder();

            builder.WriteBeginArray();
            for (int i = 0, j = tokens_.Count; i < j; i++)
            {
                IJsonToken token = tokens_[i];
                builder.WriteUnquotedString(token.AsJson());
            }
            builder.WriteEndArray();
            return(builder.ToString());
        }