/** * Encodes this object as a compact JSON string, such as: * <pre>{"query":"Pizza","locations":[94043,90210]}</pre> */ @Override public String toString() { try { JSONStringer stringer = new JSONStringer(); writeTo(stringer); return stringer.toString(); } catch (JSONException e) { return null; } }
/** * Encodes this array as a compact JSON string, such as: * <pre>[94043,90210]</pre> */ @Override public String toString() { try { JSONStringer stringer = new JSONStringer(); writeTo(stringer); return stringer.toString(); } catch (JSONException e) { return null; } }
/** * 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) throws JSONException { JSONStringer stringer = new JSONStringer(); stringer.open(JSONStringer.Scope.NULL, ""); for (int i = 0, size = values.size(); i < size; i++) { if (i > 0) { stringer.out.append(separator); } stringer.value(values.get(i)); } stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, ""); return stringer.out.toString(); }
/** * Encodes this array as a human readable JSON string for debugging, such * as: * <pre> * [ * 94043, * 90210 * ]</pre> * * @param indentSpaces the number of spaces to indent for each level of * nesting. */ public String toString(int indentSpaces) throws JSONException { 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> */ @Override public String toString() { try { JSONStringer stringer = new JSONStringer(); writeTo(stringer); return stringer.toString(); } catch (JSONException e) { return null; } }
@NonNull @Override public String toFormattedString(@NonNull CrashReportData data, @NonNull ImmutableSet<ReportField> order, @NonNull String mainJoiner, @NonNull String subJoiner, boolean urlEncode) throws JSONException { final Map<String, Object> map = data.toMap(); final JSONStringer stringer = new JSONStringer().object(); for (ReportField field : order) { stringer.key(field.toString()).value(map.remove(field.toString())); } for (Map.Entry<String, Object> entry : map.entrySet()) { stringer.key(entry.getKey()).value(entry.getValue()); } return stringer.endObject().toString(); } },
/** * Encodes this array as a compact JSON string, such as: * * <pre> * [94043,90210] * </pre> * * @return The string form of this array. */ @Override public String toString() { try { JSONStringer stringer = new JSONStringer(); writeTo(stringer); return stringer.toString(); } catch (JSONException e) { return null; } }
/** * 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) throws JSONException { JSONStringer stringer = new JSONStringer(indentSpaces); writeTo(stringer); return stringer.toString(); }
/** * 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> * * @param separator The string used to separate the returned values. * @return the conjoined values. * @throws JSONException Only if there is a coding error. */ public String join(String separator) throws JSONException { JSONStringer stringer = new JSONStringer(); stringer.open(JSONStringer.Scope.NULL, ""); for (int i = 0, size = values.size(); i < size; i++) { if (i > 0) { stringer.out.append(separator); } stringer.value(values.get(i)); } stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, ""); return stringer.out.toString(); }
/** * Encodes this array as a human readable JSON string for debugging, such as: * * <pre> * [ * 94043, * 90210 * ] * </pre> * * @param indentSpaces the number of spaces to indent for each level of nesting. * @return The string form of this array. * @throws JSONException Only if there is a coding error. */ public String toString(int indentSpaces) throws JSONException { JSONStringer stringer = new JSONStringer(indentSpaces); writeTo(stringer); return stringer.toString(); }
/** * 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. * @return The string containing the pretty form of this. * @throws JSONException On internal errors. Shouldn't happen. */ public String toString(int indentSpaces) throws JSONException { JSONStringer stringer = new JSONStringer(indentSpaces); writeTo(stringer); return stringer.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 new AssertionError(); } }
/** * 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. * @return the quoted 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 new AssertionError(); } }
static String toDeterministicString(Object o) throws JSONException { JSONStringer stringer = new JSONStringer(); addToStringer(stringer, o); return stringer.toString(); }
public static String toJson(Object object) throws Exception { JSONStringer jsonOut = new JSONStringer(); toJson(object, jsonOut); return jsonOut.toString(); }
JSONStringer json = new JSONStringer(); StringBuilder sb=new StringBuilder();
@Override public Object get(Object... args) { return new JSONStringer(); } }
System.out.println( new JSONStringer() .object() .key("jsonStringValue") .value("{\"hello\":\"world\"}") .key("naturalStringValue") .value("\"hello world\"") .endObject() .toString());
JSONStringer jsonstr = new JSONStringer() .object().key("Credential") .object().key("ref1").value("Test") .key("ref2").value("test") .key("ref3").value("test") .endObject() .key("ref4").value("data") .endObject(); Log.i("JSONStringer", jsonstr.toString());
public static String writeToJson(Form form) { JSONStringer js = new JSONStringer(); js.object(); List<Field> fields = new ArrayList<Field>(); collectVisibleFields(form, fields); fieldsToJson(js, fields); js.endObject(); return js.toString(); }