/** * Get the optional object value associated with an index. * * @param index The index must be between 0 and length() - 1. * @return An object value, or null if there is no object at that index. */ public Object opt(int index) { return (index < 0 || index >= length()) ? null : this.myArrayList.get(index); }
/** * Make a string from the contents of this JsonArray. The * <code>separator</code> string is inserted between each element. Warning: * This method assumes that the data structure is acyclical. * * @param separator A string that will be inserted between the elements. * @return a string. * @throws JsonException If the array contains an invalid number. */ public String join(String separator) throws JsonException { int len = length(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator); } sb.append(JsonObject.valueToString(this.myArrayList.get(i))); } return sb.toString(); }
/** * 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; }
int len = length(); if (len == 0) { return "[]";
/** * Produce a JsonArray containing the names of the elements of this * JsonObject. * * @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; }
/** * 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 com.restfb.json.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; }
/** * Put or replace an object value in the JsonArray. If the index is greater * than the length of the JsonArray, then null elements will be added as * necessary to pad it out. * * @param index The subscript. * @param value The value to put into the array. The value should be a Boolean, * Double, Integer, JsonArray, JsonObject, Long, or String, or the * JsonObject.NULL object. * @return this. * @throws JsonException If the index is negative or if the the value is an invalid * number. */ public JsonArray put(int index, Object value) throws JsonException { JsonObject.testValidity(value); if (index < 0) { throw new JsonException("JsonArray[" + index + "] not found."); } if (index < length()) { this.myArrayList.set(index, value); } else { while (index != length()) { put(JsonObject.NULL); } put(value); } return this; }
try { boolean b = false; int len = length();
if (((JsonArray) rawValue).length() == 0) { if (logger.isLoggable(FINER)) logger.finer("Coercing an empty JSON array " + "to an empty string for " + fieldWithAnnotation);
for (int i = 0; i < jsonArray.length(); i++) list.add(toJavaObject(jsonArray.get(i).toString(), type));
new JsonArray(makeRequest("fql.multiquery", sessionKey, parameters.toArray(new Parameter[0]))); for (int i = 0; i < jsonArray.length(); i++) { JsonObject jsonObject = jsonArray.getJsonObject(i);
@SuppressWarnings("unchecked") protected <T> Connection<T> mapToConnection(String connectionJson, Class<T> connectionType) { List<T> data = new ArrayList<T>(); String previous = null; String next = null; try { JsonObject jsonObject = new JsonObject(connectionJson); // Pull out data JsonArray jsonData = jsonObject.getJsonArray("data"); for (int i = 0; i < jsonData.length(); i++) data.add(connectionType.equals(JsonObject.class) ? (T) jsonData.get(i) : jsonMapper.toJavaObject(jsonData .get(i).toString(), connectionType)); // Pull out paging info, if present if (jsonObject.has("paging")) { JsonObject jsonPaging = jsonObject.getJsonObject("paging"); previous = jsonPaging.has("previous") ? jsonPaging.getString("previous") : null; next = jsonPaging.has("next") ? jsonPaging.getString("next") : null; } } catch (JsonException e) { throw new FacebookJsonMappingException("Unable to map connection JSON to Java objects", e); } return new Connection<T>(data, previous, next); }
for (int i = 0; i < jsonArray.length(); i++) { JsonObject jsonObject = jsonArray.getJsonObject(i);