/** * 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()); }
/** * 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); } }
/** * 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(); } }