/** * 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; } }
@Override public String toString() { String json = super.toString(); return JSONPrettifier.parse( json ); } }
/** * 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; } }
/** * 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(); }
@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 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 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(); }
/** * 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 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(); }
StringEntity entity = new StringEntity(json.toString()); entity.setContentType("application/json;charset=UTF-8"); entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
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());
HttpPost request = new HttpPost("http://10.242.48.54/restinsert/Service1.svc/save"); JSONStringer json = new JSONStringer() .object() .key("cname").value(name) .key("cmail").value(email) .endObject(); StringEntity entity = new StringEntity(json.toString(), "UTF-8"); entity.setContentType("application/json;charset=UTF-8");//text/plain;charset=UTF-8 entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8")); request.setEntity(entity); // Send request to WCF service DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(request);
/** * 将对象转换成Json字符串 * @param obj * @return */ public static String toJSON(Object obj) { JSONStringer js = new JSONStringer(); serialize(js, obj); return js.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; } }
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(); }