Пример #1
0
        /// <summary> Make a string from the contents of this JSONArray. The
        /// <code>separator</code> string is inserted between each element.
        /// Warning: This method assumes that the data structure is acyclical.
        /// </summary>
        /// <param name="separator">A string that will be inserted between the elements.
        /// </param>
        /// <returns> a string.
        /// </returns>
        /// <throws>  JSONException If the array contains an invalid number. </throws>
        public virtual System.String join(System.String separator)
        {
            int len = length();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            for (int i = 0; i < len; i += 1)
            {
                if (i > 0)
                {
                    sb.Append(separator);
                }
                sb.Append(JSONObject.valueToString(this.myArrayList[i]));
            }
            return(sb.ToString());
        }
Пример #2
0
        /// <summary> Make a prettyprinted JSON text of this JSONArray.
        /// Warning: This method assumes that the data structure is acyclical.
        /// </summary>
        /// <param name="indentFactor">The number of spaces to add to each level of
        /// indentation.
        /// </param>
        /// <param name="indent">The indention of the top level.
        /// </param>
        /// <returns> a printable, displayable, transmittable
        /// representation of the array.
        /// </returns>
        /// <throws>  JSONException </throws>
        internal virtual System.String toString(int indentFactor, int indent)
        {
            int len = length();

            if (len == 0)
            {
                return("[]");
            }
            int i;

            System.Text.StringBuilder sb = new System.Text.StringBuilder("[");
            if (len == 1)
            {
                sb.Append(JSONObject.valueToString(this.myArrayList[0], indentFactor, indent));
            }
            else
            {
                int newindent = indent + indentFactor;
                sb.Append('\n');
                for (i = 0; i < len; i += 1)
                {
                    if (i > 0)
                    {
                        sb.Append(",\n");
                    }
                    for (int j = 0; j < newindent; j += 1)
                    {
                        sb.Append(' ');
                    }
                    sb.Append(JSONObject.valueToString(this.myArrayList[i], indentFactor, newindent));
                }
                sb.Append('\n');
                for (i = 0; i < indent; i += 1)
                {
                    sb.Append(' ');
                }
            }
            sb.Append(']');
            return(sb.ToString());
        }
Пример #3
0
        /// <summary> Write the contents of the JSONArray as JSON text to a writer.
        /// For compactness, no whitespace is added.
        /// <p>
        /// Warning: This method assumes that the data structure is acyclical.
        ///
        /// </summary>
        /// <returns> The writer.
        /// </returns>
        /// <throws>  JSONException </throws>
        //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.Writer' and 'System.IO.StreamWriter' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'"
        public virtual System.IO.StreamWriter write(System.IO.StreamWriter writer)
        {
            try
            {
                bool b   = false;
                int  len = length();

                writer.Write('[');

                for (int i = 0; i < len; i += 1)
                {
                    if (b)
                    {
                        writer.Write(',');
                    }
                    System.Object v = this.myArrayList[i];
                    if (v is JSONObject)
                    {
                        ((JSONObject)v).write(writer);
                    }
                    else if (v is JSONArray)
                    {
                        ((JSONArray)v).write(writer);
                    }
                    else
                    {
                        writer.Write(JSONObject.valueToString(v));
                    }
                    b = true;
                }
                writer.Write(']');
                return(writer);
            }
            catch (System.IO.IOException e)
            {
                throw new JSONException(e);
            }
        }
Пример #4
0
 /// <summary> Append an object value.</summary>
 /// <param name="o">The object to append. It can be null, or a Boolean, Number,
 /// String, JSONObject, or JSONArray, or an object with a toJSONString()
 /// method.
 /// </param>
 /// <returns> this
 /// </returns>
 /// <throws>  JSONException If the value is out of sequence. </throws>
 public virtual JSONWriter value_Renamed(System.Object o)
 {
     return(this.append(JSONObject.valueToString(o)));
 }