/** * Get an array of field names from a JSONObject.<p> * * @param jo the JSONObject * @return an array of field names, or null if there are no names */ public static String[] getNames(JSONObject jo) { int length = jo.length(); if (length == 0) { return null; } Iterator<String> i = jo.keys(); String[] names = new String[length]; int j = 0; while (i.hasNext()) { names[j] = i.next(); j += 1; } return names; }
/** * Get an array of field names from a JSONObject.<p> * * @param jo the JSONObject * @return an array of field names, or null if there are no names */ public static String[] getNames(JSONObject jo) { int length = jo.length(); if (length == 0) { return null; } Iterator i = jo.keys(); String[] names = new String[length]; int j = 0; while (i.hasNext()) { names[j] = (String)i.next(); j += 1; } return names; }
Iterator keys = keys(); StringBuffer sb = new StringBuffer("{");
/** * Produce a JSONArray containing the names of the elements of this JSONObject.<p> * * @return a JSONArray containing the key strings, or null if the JSONObject is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator<String> keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
/** * Produce a JSONArray containing the names of the elements of this JSONObject.<p> * * @return a JSONArray containing the key strings, or null if the JSONObject is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
Iterator<String> keys = keys(); StringBuffer sb = new StringBuffer("{");
/** * Converts the given JSON object into a valid parameter map.<p> * * @param params the JSON object to convert * * @return the parameter map from the given JSON object */ public static Map<String, String[]> getParameterMapFromJSON(JSONObject params) { Map<String, String[]> result = new HashMap<String, String[]>(); Iterator<String> itKeys = params.keys(); while (itKeys.hasNext()) { String key = itKeys.next(); JSONArray paramValue = params.optJSONArray(key); result.put(key, new String[paramValue.length()]); for (int i = 0, l = paramValue.length(); i < l; i++) { result.get(key)[i] = paramValue.optString(i); } } return result; }
Iterator<String> keys = keys(); writer.write('{');
Iterator keys = keys(); writer.write('{');
keys = jo.keys(); while (keys.hasNext()) { k = keys.next().toString();
keys = jo.keys(); while (keys.hasNext()) { k = keys.next().toString();
/** * Creates an element from its serialized data.<p> * * @param data the serialized data * * @return the restored element bean * * @throws JSONException if the serialized data got corrupted */ protected CmsContainerElementBean elementFromJson(JSONObject data) throws JSONException { CmsUUID element = new CmsUUID(data.getString(FavListProp.ELEMENT.name().toLowerCase())); CmsUUID formatter = null; if (data.has(FavListProp.FORMATTER.name().toLowerCase())) { formatter = new CmsUUID(data.getString(FavListProp.FORMATTER.name().toLowerCase())); } Map<String, String> properties = new HashMap<String, String>(); JSONObject props = data.getJSONObject(FavListProp.PROPERTIES.name().toLowerCase()); Iterator<String> keys = props.keys(); while (keys.hasNext()) { String key = keys.next(); properties.put(key, props.getString(key)); } return new CmsContainerElementBean(element, formatter, properties, false); }
keys = jo.keys(); while (keys.hasNext()) { k = keys.next();
keys = jo.keys(); while (keys.hasNext()) { k = keys.next().toString();
/** * Merges the current JSON object with the given one, modifying the this.<p> * * @param jo the JSON object to merge * @param overwrite if to overwrite values * @param deep if to recurse in object values * * @throws JSONException if a value is a non-finite number * * @since 7.6 */ public void merge(JSONObject jo, boolean overwrite, boolean deep) throws JSONException { Iterator<String> it = jo.keys(); while (it.hasNext()) { String key = it.next(); if (!has(key)) { put(key, jo.get(key)); continue; } boolean recurse = deep && (jo.optJSONObject(key) != null) && (optJSONObject(key) != null); if (overwrite && !recurse) { put(key, jo.get(key)); continue; } if (recurse) { getJSONObject(key).merge(jo.getJSONObject(key), overwrite, deep); } } }