/** * 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.sbOut.Append(separator); } stringer.Value(values[i]); } stringer.Close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, ""); return(stringer.sbOut.ToString()); }
/** * 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; } }