Esempio n. 1
0
        /**
         * Encodes this object as a human readable JSON string for debugging, such
         * as:
         * <pre>
         * {
         *     "query": "Pizza",
         *     "locations": [
         *         94043,
         *         90210
         *     ]
         * }</pre>
         *
         * @param indentSpaces the number of spaces to indent for each level of
         *     nesting.
         */
        public string ToString(int indentSpaces)
        {
            JsonStringer stringer = new JsonStringer(indentSpaces);

            WriteTo(stringer);
            return(stringer.ToString());
        }
Esempio n. 2
0
 internal void WriteTo(JsonStringer stringer)
 {
     stringer.Obj();
     foreach (KeyValuePair <string, object> entry in nameValuePairs)
     {
         stringer.Key(entry.Key).Value(entry.Value);
     }
     stringer.EndObject();
 }
Esempio n. 3
0
 internal void WriteTo(JsonStringer stringer)
 {
     stringer.Array();
     foreach (object value in values)
     {
         stringer.Value(value);
     }
     stringer.EndArray();
 }
Esempio n. 4
0
 /**
  * Encodes this object as a compact JSON string, such as:
  * <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
  */
 public override string ToString()
 {
     try {
         JsonStringer stringer = new JsonStringer();
         WriteTo(stringer);
         return(stringer.ToString());
     } catch (JsonException) {
         return(null);
     }
 }
Esempio n. 5
0
 /**
  * Encodes {@code data} as a JSON string. This applies quotes and any
  * necessary character escaping.
  *
  * @param data the string to encode. Null will be interpreted as an empty
  *     string.
  */
 public static string Quote(String data)
 {
     if (data == null)
     {
         return("\"\"");
     }
     try {
         JsonStringer stringer = new JsonStringer();
         stringer.Open(JsonStringer.Scope.NULL, "");
         stringer.Value(data);
         stringer.Close(JsonStringer.Scope.NULL, JsonStringer.Scope.NULL, "");
         return(stringer.ToString());
     } catch (JsonException) {
         throw new ApplicationException();
     }
 }
Esempio n. 6
0
        /**
         * Returns a new string by alternating this array's values with {@code
         * separator}. This array's string values are quoted and have their special
         * characters escaped. For example, the array containing the strings '12"
         * pizza', 'taco' and 'soda' joined on '+' returns this:
         * <pre>"12\" pizza"+"taco"+"soda"</pre>
         */
        public string Join(string separator)
        {
            JsonStringer stringer = new JsonStringer();

            stringer.Open(JsonStringer.Scope.NULL, "");
            for (int i = 0, size = values.Count; i < size; i++)
            {
                if (i > 0)
                {
                    stringer.output.Append(separator);
                }
                stringer.Value(values[i]);
            }
            stringer.Close(JsonStringer.Scope.NULL, JsonStringer.Scope.NULL, "");
            return(stringer.output.ToString());
        }