Ejemplo n.º 1
0
 /**
  * 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 < this.length()) {
     this.myArrayList.set(index, value);
   } else {
     while (index != this.length()) {
       this.put(JSONObject.NULL);
     }
     this.put(value);
   }
   return this;
 }
Ejemplo n.º 2
0
 /**
  * Append a double value. This increases the array's length by one.
  *
  * @param value A double value.
  * @throws JSONException if the value is not finite.
  * @return this.
  */
 public JSONArray put(double value) throws JSONException {
   Double d = new Double(value);
   JSONObject.testValidity(d);
   this.put(d);
   return this;
 }