Code example for JsonArray

0
			final JsonObject json = new JsonObject();
			json.addProperty("total", pagesCount); // total number of pages
			json.addProperty("records", users.size()); // total number of users
			json.addProperty("page", page); // current page
			 
			final JsonArray rows = new JsonArray();
			 
			int startI = (page - 1) * rowsPerPage;
			int endI = Math.min(startI + rowsPerPage, users.size());
			for(int i = startI; i < endI; i++) {			
				final JsonObject rowObj = toJson(users.get(i));
				rows.add(rowObj);
			} 
			 
			json.add("rows", rows);
			 
			writeResponse(response, json);
		} catch (final LdapException ex) {			
			throw new ServletException("Error processing users list", ex);
		} catch (final CursorException ex) {
Experience pair programming with AI  Get Codota for Java