Example #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());
        }
Example #2
0
        /// <inheritdoc/>
        public string AsJson()
        {
            JsonStringBuilder builder = new JsonStringBuilder();

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