private void writeArray(JSONArray jsonarray) throws JSONException {

// JSONzip has three encodings for arrays:
// The array is empty (zipEmptyArray).
// First value in the array is a string (zipArrayString).
// First value in the array is not a string (zipArrayValue).

        boolean stringy = false;
        int length = jsonarray.length();
        if (length == 0) {
            write(zipEmptyArray, 3);
        } else {
            Object value = jsonarray.get(0);
            if (value == null) {
                value = JSONObject.NULL;
            }
            if (value instanceof String) {
                stringy = true;
                write(zipArrayString, 3);
                writeString((String) value);
            } else {
                write(zipArrayValue, 3);
                writeValue(value);
            }
            for (int i = 1; i < length; i += 1) {
                if (probe) {
                    log();
                }
                value = jsonarray.get(i);
                if (value == null) {
                    value = JSONObject.NULL;
                }
                if (value instanceof String != stringy) {
                    zero();
                }
                one();
                if (value instanceof String) {
                    writeString((String) value);
                } else {
                    writeValue(value);
                }
            }
            zero();
            zero();

        }
    }