/** * Get the optional object value associated with an index. * @param index must be between 0 and length() - 1 * @return An object value, or null if there is no * object at that index. */ private Object opt(int index) { if (index < 0 || index >= this.size()) { return null; } return myArrayList.get(index); }
/** * Get the optional object value associated with an index. * @param index must be between 0 and length() - 1 * @return An object value, or null if there is no * object at that index. */ private Object opt(int index) { if (index < 0 || index >= this.size()) { return null; } return myArrayList.get(index); }
/** * Get this entire array as a String array. * * @webref jsonarray:method * @brief Gets the entire array as an array of Strings * @see JSONArray#getIntArray() */ public String[] getStringArray() { String[] outgoing = new String[size()]; for (int i = 0; i < size(); i++) { outgoing[i] = getString(i); } return outgoing; }
/** * Get this entire array as a String array. * * @webref jsonarray:method * @brief Gets the entire array as an array of Strings * @see JSONArray#getIntArray() */ public String[] getStringArray() { String[] outgoing = new String[size()]; for (int i = 0; i < size(); i++) { outgoing[i] = getString(i); } return outgoing; }
/** * Get this entire array as an int array. Everything must be an int. * * @webref jsonarray:method * @brief Gets the entire array as array of ints * @see JSONArray#getStringArray() */ public int[] getIntArray() { int[] outgoing = new int[size()]; for (int i = 0; i < size(); i++) { outgoing[i] = getInt(i); } return outgoing; }
/** * Get this entire array as an int array. Everything must be an int. * * @webref jsonarray:method * @brief Gets the entire array as array of ints * @see JSONArray#getStringArray() */ public int[] getIntArray() { int[] outgoing = new int[size()]; for (int i = 0; i < size(); i++) { outgoing[i] = getInt(i); } return outgoing; }
/** * 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 acyclic. * @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) { int len = this.size(); StringBuffer sb = new StringBuffer(); 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(); } }
/** * 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 acyclic. * @param separator A string that will be inserted between the elements. * @return a string. * @throws RuntimeException If the array contains an invalid number. */ public String join(String separator) { int len = this.size(); 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(); } }
/** * 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 RuntimeException If the index is negative or if the the value is * an invalid number. */ private JSONArray set(int index, Object value) { JSONObject.testValidity(value); if (index < 0) { throw new RuntimeException("JSONArray[" + index + "] not found."); } if (index < this.size()) { this.myArrayList.set(index, value); } else { while (index != this.size()) { this.append(JSONObject.NULL); } this.append(value); } return this; }
/** * 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. */ private JSONArray set(int index, Object value) { JSONObject.testValidity(value); if (index < 0) { throw new RuntimeException("JSONArray[" + index + "] not found."); } if (index < this.size()) { this.myArrayList.set(index, value); } else { while (index != this.size()) { this.append(JSONObject.NULL); } this.append(value); } return this; }
try { boolean commanate = false; int length = this.size(); writer.write('[');
try { boolean commanate = false; int length = this.size(); writer.write('[');