Transform a JSON Array into a {@link List}.

@param jsonArray The {@link JSONArray} to convert
@return List of values
339492
protected List<String> parseArray(final JSONArray jsonArray) {
		final List<String> arrayContents = new ArrayList<>();

		if (jsonArray != null) {
			for (int i = 0; i < jsonArray.length(); i++) {
				final String element = jsonArray.getString(i);
				if (element != null) {
					arrayContents.add(element);
				}
			}
		}

		return arrayContents;
	}
660854
public JSONArray getJSONArray(int index) throws JSONException {
    Object o = get(index);
    if (o instanceof JSONArray) {
      return (JSONArray) o;
    }
    throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
  }
948882
@SuppressWarnings("unchecked")
    public static <T> T[] jsonArrayToArray(final JSONArray jsonArray, final Class<? extends T[]> newType) {
        if (null == jsonArray) {
            return (T[]) new Object[]{};
        }

        final int newLength = jsonArray.length();
        final Object[] original = new Object[newLength];

        for (int i = 0; i < newLength; i++) {
            original[i] = jsonArray.opt(i);
        }

        return Arrays.copyOf(original, newLength, newType);
    }
1087148
@Nullable
    static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) {
        if (jsonArray == null) {
            return null;
        }

        List<Object> objectList = new ArrayList<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            try {
                Object ob = jsonArray.get(i);
                if (ob instanceof JSONArray) {
                    objectList.add(jsonArrayToList((JSONArray) ob));
                } else if (ob instanceof JSONObject) {
                    Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob);
                    if (objectMap != null) {
                        objectList.add(objectMap);
                    }
                } else {
                    if (NULL.equals(ob)) {
                        continue;
                    }
                    objectList.add(ob);
                }
            } catch (JSONException ignored) {
                // Nothing to do in this case.
            }
        }
        return objectList;
    }
192975
public static List<Object> array2ObjectList(final Object array) {
        final int length = Array.getLength(array);
        final List<Object> list = new ArrayList<Object>(length);
        for (int i = 0; i < length; ++i) {
            list.add(Array.get(array, i));
        }
        return list;
    }
1159770
public List<T> parseList(byte[] byteArray) throws IOException {
        JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(byteArray);
        jsonParser.nextToken();
        return parseList(jsonParser);
    }
1230831
private JSONValue toJsonStringList(Collection<? extends Object> list) {

        if (null != list) {
            JSONArray array = new JSONArray();
            for (Object o : list) {
                array.set(array.size(), new JSONString(o.toString()));
            }
            return array;
        } else {
            return null;
        }
    }
78506
private List<String> hashtagsFromArray(JSONObject json, String array) {
        if (json.containsKey(array)) {
            JSONArray hashtagsArray = json.getJSONArray(array);
            List<String> result = new ArrayList<String>(hashtagsArray.size());
            for (Object tag : hashtagsArray) {
                result.add(tag.toString());
            }
            return result;
        }
        return Collections.emptyList();
    }
781366
private JSONArray array2JSON(JSONArray ja, Object[] array) {
        for (int i = 0; i < array.length; i++) {
            // array entry is a Map
            if (array[i] instanceof Map) {
                //if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                //    Tr.debug(tc, "array entry is a Map, calling map2JSON", array[i]);
                //}
                ja.add(map2JSON(new JSONObject(), (Map<String, Object>) array[i]));
            }
            // array entry is an array
            else if (array[i].getClass().isArray()) {
                //if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                //    Tr.debug(tc, "array entry is a array, calling array2JSON", array[i]);
                //}
                ja.add(array2JSON(new JSONArray(), (Object[]) array[i]));
            }
            // else array entry is a "simple" value
            else {
                //if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                //    Tr.debug(tc, "array entry is a simple value, adding to ja", array[i]);
                //}
                ja.add(array[i]);
            }
        }
        return ja;
    }
727625
public static String listToJson(List<?> list) {
        JSONArray array = new JSONArray();
        if (Checker.isNotEmpty(list)) {
            array.addAll(list);
        }
        return formatJson(array.toString());
    }
672074
public JsonArray getAsArray() {
		if (!(value instanceof JsonArray)) {
			JsonArray val = new JsonArray();
			val.add(value);
			value = val;
		}
		return (JsonArray)value;
	}
849757
public static String[] toArray(List<String> list) {
        String[] ret = new String[list.size()];
        for (int i = 0; i < ret.length; i++)
            ret[i] = list.get(i);
        return ret;
    }
512354
public static <T> List<T> toList(Object array, Class<T> clazz) {
        List<T> list = new ArrayList<>();
        for (Object o : toObjectArray(array)) {
            list.add(Reflection.toType(o, clazz));
        }
        return list;
    }
778835
public JSONArray jsonifyValues() {
        JSONArray jValues = new JSONArray();
        for (ValueEntry vEntry : values) {
            JSONObject o = new JSONObject();
            o.put("value",vEntry.getValue());
            o.put("timestamp",vEntry.getTimestamp());
            jValues.add(o);
        }
        return jValues;
    }
66659
public static Object toArray( JSONArray jsonArray, Object root, JsonConfig jsonConfig ) {
      Class objectClass = root.getClass();
      if( jsonArray.size() == 0 ){
         return Array.newInstance( objectClass, 0 );
      }

      int[] dimensions = JSONArray.getDimensions( jsonArray );
      Object array = Array.newInstance( objectClass == null ? Object.class : objectClass,
            dimensions );
      int size = jsonArray.size();
      for( int i = 0; i < size; i++ ){
         Object value = jsonArray.get( i );
         if( JSONUtils.isNull( value ) ){
            Array.set( array, i, null );
         }else{
            Class type = value.getClass();
            if( JSONArray.class.isAssignableFrom( type ) ){
               Array.set( array, i, toArray( (JSONArray) value, root, jsonConfig ) );
            }else if( String.class.isAssignableFrom( type )
                  || Boolean.class.isAssignableFrom( type ) || JSONUtils.isNumber( type )
                  || Character.class.isAssignableFrom( type )
                  || JSONFunction.class.isAssignableFrom( type ) ){
               if( objectClass != null && !objectClass.isAssignableFrom( type ) ){
                  value = JSONUtils.getMorpherRegistry()
                        .morph( objectClass, value );
               }
               Array.set( array, i, value );
            }else{
               try{
                  Object newRoot = jsonConfig.getNewBeanInstanceStrategy()
                        .newInstance( root.getClass(), null );
                  Array.set( array, i, JSONObject.toBean( (JSONObject) value, newRoot, jsonConfig ) );
               }catch( JSONException jsone ){
                  throw jsone;
               }catch( Exception e ){
                  throw new JSONException( e );
               }
            }
         }
      }
      return array;
   }
51904
public JSONWriter array() {
        if (this.mode == INIT || this.mode == OBJECT || this.mode == ARRAY) {
            this.push(ARRAY);
            this.append("[");
            this.comma = false;
            return this;
        }
        throw new JSONException("Misplaced array: expected mode of INIT, OBJECT or ARRAY but was " + this.mode);
    }
221359
public T[] toArray(T[] tArray) {
        List<T> array = new ArrayList<T>(100);
        for (Iterator<T> it = iterator(); it.hasNext();) {
            T val = it.next();
            if (val != null) array.add(val);
        }
        return array.toArray(tArray);
    }