Пример #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());
        }
Пример #2
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 e)
     {
         return(null);
     }
 }
Пример #3
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 e)
     {
         throw e;
     }
 }