private boolean isSupported(JSONObject obj) { try { if (obj.has(PROTOCOLS)) { JSONArray protocols = obj.getJSONArray(PROTOCOLS); for (int i = 0; i < protocols.length(); i++) { String protocol = protocols.getString(i); if (PROTOCOL_VERSION_7.equals(protocol)) { return true; } } } } catch (JSONException e) { } return false; }
private boolean isSupported(JSONObject obj) { try { if (obj.has(PROTOCOLS)) { JSONArray protocols = obj.getJSONArray(PROTOCOLS); for (int i = 0; i < protocols.length(); i++) { String protocol = protocols.getString(i); if (PROTOCOL_VERSION_7.equals(protocol)) { return true; } } } } catch (JSONException e) { } return false; }
public Parameters(SlingHttpServletRequest request) throws IOException, JSONException { final JSONObject json = new JSONObject(request.getParameter("params")); final List<String> customProperties = new ArrayList<String>(); final List<String> groups = new ArrayList<String>(); groupFilter = json.getString(GROUP_FILTER); JSONArray groupsJSON = json.getJSONArray(GROUPS); for (int i = 0; i < groupsJSON.length(); i++) { groups.add(groupsJSON.getString(i)); } this.groups = groups.toArray(new String[groups.size()]); JSONArray customPropertiesJSON = json.getJSONArray(CUSTOM_PROPERTIES); for (int i = 0; i < customPropertiesJSON.length(); i++) { JSONObject tmp = customPropertiesJSON.getJSONObject(i); String relativePropertyPath = tmp.optString(RELATIVE_PROPERTY_PATH); if (StringUtils.isNotBlank(relativePropertyPath)) { customProperties.add(relativePropertyPath); } } this.customProperties = customProperties.toArray(new String[customProperties.size()]); }
JSONArray names = jsonObject.names(); for (int i = 0; names != null && i < names.length(); i++) { final String name = names.getString(i); if (!IGNORED_NAMES.contains(name)) { Object obj = jsonObject.get(name); final String name = names.getString(i); if (!IGNORED_NAMES.contains(name)) { Object obj = jsonObject.get(name);
String[] values = new String[array.length()]; for (int i = 0; i < values.length; i++) { values[i] = array.getString(i);
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }