public JSONArray parseArray(String input) {
    init(input);
    level = 0;
    JSONArray list = new JSONArray();
    try {
      if ( expect('[', true) ) {
	parseArrayItems(list);
      }
      if ( level != 0 ) {
	addError("unmatched braces or brackets");
      }
    }
    catch (EndOfInputException e) {
      String msg = "unexpected end of input";
      addError(msg);
    }
    if ( hasNext() ) {
      addError("unexpected characters after closing brace");
    }
    return list;
  }