void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
private static void addToStringer(JSONStringer stringer, Object o) throws JSONException { if (o instanceof JSONObject) { stringer.object(); JSONObject object = (JSONObject) o; Iterator<String> keyIterator = object.keys(); ArrayList<String> keys = new ArrayList<>(); while (keyIterator.hasNext()) { keys.add(keyIterator.next()); } Collections.sort(keys); for (String key : keys) { stringer.key(key); addToStringer(stringer, object.opt(key)); } stringer.endObject(); return; } if (o instanceof JSONArray) { JSONArray array = (JSONArray) o; stringer.array(); for (int i = 0; i < array.length(); ++i) { addToStringer(stringer, array.get(i)); } stringer.endArray(); return; } stringer.value(o); }
toJson(e, json_out); json_out.endArray();
/** * 序列化数组 * @param js * @param array */ private static void serializeArray(JSONStringer js, Object array) { try { js.array(); for ( int i = 0; i < Array.getLength(array); ++i) { Object o = Array.get(array, i); serialize(js, o); } js.endArray(); } catch (Exception e) { e.printStackTrace(); } }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
/** * 序列化集合 * @param js * @param collection */ private static void serializeCollect(JSONStringer js, Collection<?> collection) { try { js.array(); for (Object o : collection) { serialize(js, o); } js.endArray(); } catch (Exception e) { e.printStackTrace(); } }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
void writeTo(JSONStringer stringer) throws JSONException { stringer.array(); for (Object value : values) { stringer.value(value); } stringer.endArray(); }
public static void writeStringArray(JSONStringer writer, String key, List<String> values) throws JSONException { if (values != null) { writer.key(key).array(); for (String value : values) { writer.value(value); } writer.endArray(); } } }
protected final <T> void set(String key, T[] value) { if (value == null) { return; } jsonWriter.key(key).array(); for (T item : value) { if (item != null) { jsonWriter.value(item); } } jsonWriter.endArray(); }
public static void annotationPropertyValueAsJson(JSONStringer js, Object propertyValue) { if(propertyValue instanceof Annotation) { annotationToJson(js, (Annotation) propertyValue); } else if(propertyValue instanceof Class) { js.value(propertyValue.toString()); } else if(propertyValue != null && propertyValue.getClass().isArray()) { js.array(); //TODO handle primitive arrays. Elements annotations only have String[] arrays currently. for (Object element : (Object[]) propertyValue) { annotationPropertyValueAsJson(js, element); } js.endArray(); } else { js.value(propertyValue); } }
public static void annotationPropertyValueAsJson(JSONStringer js, Object propertyValue) { if(propertyValue instanceof Annotation) { annotationToJson(js, (Annotation) propertyValue); } else if(propertyValue instanceof Class) { js.value(propertyValue.toString()); } else if(propertyValue != null && propertyValue.getClass().isArray()) { js.array(); //TODO handle primitive arrays. Elements annotations only have String[] arrays currently. for (Object element : (Object[]) propertyValue) { annotationPropertyValueAsJson(js, element); } js.endArray(); } else { js.value(propertyValue); } }
private static void writeProperties(JSONStringer writer, Map<String, Object> properties) throws JSONException { if (properties != null) { writer.key(PROPERTIES).array(); for (Map.Entry<String, Object> property : properties.entrySet()) { writer.object(); JSONUtils.write(writer, PROPERTY_NAME, property.getKey()); writePropertyValue(writer, property.getValue()); writer.endObject(); } writer.endArray(); } else { throw new JSONException("Properties cannot be null"); } }
public static void putMap(String key, Map<Integer, String> age2nameMap) { if (age2nameMap != null) { JSONStringer jsonStringer = new JSONStringer(); try { jsonStringer.array(); for (Integer integer : age2nameMap.keySet()) { jsonStringer.object(); jsonStringer.key("age"); jsonStringer.value(integer); jsonStringer.key("name"); jsonStringer.value(age2nameMap.get(integer)); jsonStringer.endObject(); } jsonStringer.endArray(); } catch (JSONException e) { e.printStackTrace(); } sp.edit().putString(key, jsonStringer.toString()).commit(); } }
public static void writeArray(JSONStringer writer, String key, List<? extends Model> value) throws JSONException { if (value != null) { writer.key(key).array(); for (Model model : value) { writer.object(); model.write(writer); writer.endObject(); } writer.endArray(); } }
@NonNull @Override public String serializeContainer(@NonNull LogContainer logContainer) throws JSONException { /* Init JSON serializer. */ JSONStringer writer = new JSONStringer(); /* Start writing JSON. */ writer.object(); writer.key(LOGS).array(); for (Log log : logContainer.getLogs()) { writeLog(writer, log); } writer.endArray(); writer.endObject(); return writer.toString(); }
public static JSONWriter classAccessorToJson(ClassAccessor accessor, JSONStringer js) { js.object(); js.key("name").value(accessor.getName()); js.key("keyProperties").array(); for(PropertyAccessor p : accessor.getKeyProperties()) { js.value(p.getName()); } js.endArray(); js.key("properties").array(); for(PropertyAccessor p : accessor.getProperties()) { propertyAccessorToJson(js, p); } js.endArray(); js.key("annotations").array(); for(Annotation ann : accessor.getAnnotations()) { annotationToJson(js, ann); } js.endArray(); return js.endObject(); } }