List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.saludtec.web.PlanesDeTratamientoWeb.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String servicio = request.getRequestURI().replace("/HCEMed/PlanesDeTratamiento/", ""); switch (servicio) { case "guardar": guardarPlanTratamiento(request).writeJSONString(out); break; case "editar": editarPlanTratamiento(request).writeJSONString(out); break; case "traer": traerPlanTratamiento(request).writeJSONString(out); break; case "listar": listarPlanesDeTratamientoPaciente(request).writeJSONString(out); break; case "listarFecha": listarPlanesDeTratamientoFecha(request).writeJSONString(out); break; default:// www. j a v a 2 s . c om obj = new JSONObject(); objArray = new JSONArray(); obj.put("error", "404 - El servicio " + servicio + " no existe"); objArray.add(obj); objArray.writeJSONString(out); break; } } }
From source file:org.kitodo.data.index.elasticsearch.type.ProjectType.java
@SuppressWarnings("unchecked") @Override/* w w w . ja v a 2 s . c o m*/ public HttpEntity createDocument(Project project) { LinkedHashMap<String, String> orderedProjectMap = new LinkedHashMap<>(); orderedProjectMap.put("name", project.getTitle()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String startDate = project.getStartDate() != null ? dateFormat.format(project.getStartDate()) : null; orderedProjectMap.put("startDate", startDate); String endDate = project.getEndDate() != null ? dateFormat.format(project.getEndDate()) : null; orderedProjectMap.put("endDate", endDate); String numberOfPages = project.getNumberOfPages() != null ? project.getNumberOfPages().toString() : "null"; orderedProjectMap.put("numberOfPages", numberOfPages); String numberOfVolumes = project.getNumberOfVolumes() != null ? project.getNumberOfVolumes().toString() : "null"; orderedProjectMap.put("numberOfVolumes", numberOfVolumes); String archived = project.getProjectIsArchived() != null ? project.getProjectIsArchived().toString() : "null"; orderedProjectMap.put("archived", archived); JSONObject projectObject = new JSONObject(orderedProjectMap); JSONArray processes = new JSONArray(); List<Process> projectProcesses = project.getProcesses(); for (Process process : projectProcesses) { JSONObject processObject = new JSONObject(); processObject.put("id", process.getId().toString()); processes.add(processObject); } projectObject.put("processes", processes); JSONArray users = new JSONArray(); List<User> projectUsers = project.getUsers(); for (User user : projectUsers) { JSONObject userObject = new JSONObject(); userObject.put("id", user.getId().toString()); users.add(userObject); } projectObject.put("users", users); JSONArray projectFileGroups = new JSONArray(); List<ProjectFileGroup> projectProjectFileGroups = project.getProjectFileGroups(); for (ProjectFileGroup projectFileGroup : projectProjectFileGroups) { JSONObject projectFileGroupObject = new JSONObject(); projectFileGroupObject.put("name", projectFileGroup.getName()); projectFileGroupObject.put("path", projectFileGroup.getPath()); projectFileGroupObject.put("mimeType", projectFileGroup.getMimeType()); projectFileGroupObject.put("suffix", projectFileGroup.getSuffix()); projectFileGroupObject.put("folder", projectFileGroup.getFolder()); projectFileGroups.add(projectFileGroupObject); } projectObject.put("projectFileGroups", projectFileGroups); return new NStringEntity(projectObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:me.timothy.ddd.entities.EntityManager.java
public void saveEntities(FileWriter fw) throws IOException { JSONArray jArr = new JSONArray(); JSONObject jObj;/*w w w.j a va 2 s . c om*/ for (Entity e : entities) { EntityInfo ei = e.getEntityInfo(); jObj = new JSONObject(); ei.saveTo(jObj); jArr.add(jObj); } DDDUtils.writeJSONPretty(fw, jArr); }
From source file:com.mobicage.rogerthat.form.AbstractSelectWidget.java
@Override @SuppressWarnings("unchecked") public JSONObject toJSONObject() { JSONObject result = new JSONObject(); JSONArray choicesArray = new JSONArray(); for (Choice choice : choices) { choicesArray.add(choice.toJSONObject()); }//w w w . j a v a2 s. com result.put("choices", choicesArray); return result; }
From source file:edu.vt.vbi.patric.common.ExpressionDataCollection.java
public ExpressionDataCollection(String path, String token) { sample = new JSONArray(); expression = new JSONArray(); expressionFileName = new ArrayList<>(); sampleFileName = new ArrayList<>(); mappingFileName = new ArrayList<>(); WORKSPACE_API_URL = System.getProperty("workspaceServiceURL", "http://p3.theseed.org/services/Workspace"); WORKSPACE_TOKEN = token;//from w w w . ja v a 2s . c om try { org.patricbrc.Workspace.Workspace serviceWS = new org.patricbrc.Workspace.Workspace(WORKSPACE_API_URL, WORKSPACE_TOKEN); get_params gp = new get_params(); gp.objects = Arrays.asList(path.split(",")); gp.metadata_only = 1; gp.adminmode = 0; LOGGER.trace("reading collection: {}", gp.objects); List<Workspace_tuple_2> r = serviceWS.get(gp); for (Workspace_tuple_2 item : r) { ObjectMeta meta = item.e_1; Map<String, Object> autoMeta = meta.e_9; List<Object> outputFiles = (List) autoMeta.get("output_files"); for (Object outputFile : outputFiles) { LOGGER.trace("reading output file: {}", outputFile); if (outputFile instanceof String) { String filename = (String) outputFile; if (filename.contains("expression.json")) { expressionFileName.add(filename); } else if (filename.contains("sample.json")) { sampleFileName.add(filename); } else if (filename.contains("mapping.json")) { mappingFileName.add(filename); } } else { String filename = (String) ((List) outputFile).get(0); if (filename.contains("expression.json")) { expressionFileName.add(filename); } else if (filename.contains("sample.json")) { sampleFileName.add(filename); } else if (filename.contains("mapping.json")) { mappingFileName.add(filename); } } } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
From source file:modelo.ParametrizacionManagers.TiposContactos.java
/** * SELECT/*w w w .j a va 2 s . c om*/ * Obtiene la informacion de una unidad de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getTiposContactos(String descripcion) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiposContactos seleccionar = new SeleccionarTiposContactos(); ResultSet rst = seleccionar.getTiposContactos(descripcion); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONArray jsonArreglo = new JSONArray(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); seleccionar.desconectar(); return jsonArreglo; }
From source file:modelo.UsuariosManagers.Usuarios.java
public JSONArray seleccionarUsuarios(String usuario, String rol, String codigo) throws SQLException { SeleccionarUsuarios select = new SeleccionarUsuarios(); ResultSet rset = select.getUsuarios(usuario, rol, codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getInt("PK_CODIGO")); jsonObject.put("descripcion", rset.getString("VAR_USUARIO")); jsonObject.put("rol", rset.getString("VAR_ROL")); jsonObject.put("idRol", rset.getInt("FK_ROL")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/*w w w . j av a 2s . c o m*/ select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }
From source file:ServiceController.java
public String setRequest(String key_, String authentication, String hostid) { // create json object for apiinfo.version JSONArray list = new JSONArray(); JSONObject jsonObj = new JSONObject(); JSONObject search = new JSONObject(); JSONObject params = new JSONObject(); jsonObj.put("jsonrpc", "2.0"); jsonObj.put("method", "item.get"); params.put("output", "extend"); params.put("hostid", hostid); params.put("search", search); params.put("sortfield", "name"); search.put("key_", key_); jsonObj.put("params", params); jsonObj.put("auth", authentication);// todo jsonObj.put("id", new Integer(1)); return jsonObj.toString(); }
From source file:com.saludtec.web.TratamientosWeb.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String servicio = request.getRequestURI().replace("/HCEMed/Tratamientos/", ""); switch (servicio) { case "guardar": guardarTratamiento(request).writeJSONString(out); break; case "eliminar": eliminarTratamiento(request).writeJSONString(out); break; case "traerFecha": listarTratamientosFecha(request).writeJSONString(out); break; case "listar": listarTratamientosPaciente(request).writeJSONString(out); break; case "listarProcedimientosAdmin": ProcedimientosAdmin procedimientos = new ProcedimientosAdmin(); procedimientos.listar(request).writeJSONString(out); break; default://from w ww. j a v a 2 s. c o m obj = new JSONObject(); objArray = new JSONArray(); obj.put("error", "404 - El servicio " + servicio + " no existe"); objArray.add(obj); objArray.writeJSONString(out); break; } } }
From source file:modelo.ParametrizacionManagers.MotivosVisitas.java
/** * SELECT/* w w w .j a v a 2s. c om*/ * Obtiene la informacion de una unidad de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getMotivosVisitas(String descripcion) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarMotivosVisitas seleccionar = new SeleccionarMotivosVisitas(); ResultSet rst = seleccionar.getMotivosVisitas(descripcion); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONArray jsonArreglo = new JSONArray(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } seleccionar.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }