示例#1
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();
     }
 }
示例#2
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());
        }