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(); }
json_out.array(); for (Object e : (ArrayList) value) { toJson(e, json_out);
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); }
/** * 序列化数组 * @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(); } } }
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(); } }
JSONStringer result = new JSONStringer(); JSONWriter array = result.array(); for (long i = start; i <= end; i = i + day) { ttm.put("$gte", "" + i); ttm.put("$lte", "" + (i + day)); //code code code int count = statisticCollection.find(query).count(); try { array.object().key("ttm").value(i).key("count").value(count).endObject(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { array.endArray(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }
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(); }
json.array(); for (Vector2 vertex : polygon.vertices) json.object().key("x").value(vertex.x).key("y").value(vertex.y).endObject();