List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.wso2.mobile.mdm.api.TrackCallSMS.java
/** * Returns a JSONArray of SMS objects Ex: [{number:"0772345666", date:"dd/MM/yyyy hh:mm:ss.SSS", content:"Hello"}] * //from w w w .j av a 2 s.co m * @param type * - Folder type should be passed in (1 for Inbox, 2 for Sent box) */ public JSONArray getSMS(int type) { JSONArray jsonArray = null; try { Uri uriSms = Uri.parse("content://sms"); Cursor cursor = cr.query(uriSms, new String[] { "_id", "address", "date", "body", "type", "read" }, "type=" + type, null, "date" + " COLLATE LOCALIZED ASC"); if (cursor != null) { cursor.moveToLast(); if (cursor.getCount() > 0) { jsonArray = new JSONArray(); do { JSONObject jsonObj = new JSONObject(); String date = cursor.getString(cursor.getColumnIndex("date")); Long timestamp = Long.parseLong(date); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp); DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); jsonObj.put("number", cursor.getString(cursor.getColumnIndex("address"))); jsonObj.put("date", formatter.format(calendar.getTime())); /*jsonObj.put("content", cursor.getString(cursor.getColumnIndex("body")));*/ //jsonObj.put("content","Testing SMS"); jsonArray.add(jsonObj); } while (cursor.moveToPrevious()); } } } catch (Exception ex) { ex.printStackTrace(); } return jsonArray; }
From source file:com.saludtec.web.GaleriaWeb.java
private JSONArray editarGaleria(HttpServletRequest request) { Galeria galeria = new Galeria(); Pacientes paciente = ejbPaciente.traer(Integer.parseInt(request.getParameter("idPaciente"))); galeria.setIdPaciente(paciente);/* www . j a v a 2 s . c om*/ galeria.setFoto(request.getParameter("foto")); galeria.setFecha(request.getParameter("fecha")); galeria.setHora(request.getParameter("hora")); galeria.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS galeria = ejbGaleria.editar(galeria); obj = new JSONObject(); objArray = new JSONArray(); if (galeria != null) { obj.put("mensaje", "Registro con id " + galeria.getIdFoto() + " editado"); objArray.add(obj); } else { obj.put("error", "no se pudo editar la foto"); objArray.add(obj); } return objArray; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.ISTConnectDA.java
public ActionForward getBasicUserData(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { if (doLogin(mapping, actionForm, request, response)) { final String istID = (String) getFromRequest(request, "istID"); final Person person = Person.readPersonByUsername(istID); final JSONObject jsonObject = new JSONObject(); if (person != null) { jsonObject.put("externalId", person.getExternalId()); jsonObject.put("className", person.getClass().getName()); jsonObject.put("email", person.getEmailForSendingEmails()); jsonObject.put("partyName", person.getPartyName().toString()); jsonObject.put("nickname", person.getNickname()); JSONArray jsonList = new JSONArray(); for (final net.sourceforge.fenixedu.domain.Role role : person.getPersonRolesSet()) { jsonList.add(role.getRoleType().getName()); }//from w w w . j a v a 2 s . c o m jsonObject.put("roles", jsonList); } writeJSONObject(response, jsonObject); } else { response.sendError(404, "Not authorized"); } return null; }
From source file:com.aerothai.database.device.DeviceService.java
public JSONObject GetDeviceAt(int id) throws Exception { Connection dbConn = null;/*from www .j a v a 2 s . com*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "listat"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM device where iddevice = " + id; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("iddevice")); jsonData.put("idunit", rs.getString("idunit")); jsonData.put("iddevice_type", rs.getString("iddevice_type")); jsonData.put("idmodel", rs.getString("idmodel")); jsonData.put("idaccessory", rs.getString("idaccessory")); jsonData.put("asset_no", rs.getString("asset_no")); jsonData.put("serial_no", rs.getString("serial_no")); jsonData.put("ip_address", rs.getString("ip_address")); jsonData.put("mac_address", rs.getString("mac_address")); jsonData.put("computer_name", rs.getString("computer_name")); jsonData.put("os", rs.getString("os")); jsonData.put("firmware", rs.getString("firmware")); jsonData.put("vendor", rs.getString("vendor")); jsonData.put("customer", rs.getString("customer")); jsonData.put("address", rs.getString("address")); jsonData.put("location", rs.getString("location")); jsonData.put("insert_date", rs.getString("insert_date")); jsonData.put("receive_date", rs.getString("receive_date")); jsonData.put("exp_date", rs.getString("exp_date")); jsonData.put("image", rs.getString("image")); jsonData.put("id_door", rs.getString("id_door")); jsonData.put("in_out_side", rs.getString("in_out_side")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj; }
From source file:com.xtructure.xevolution.tool.data.AbstractGenealogyData.java
/** * Process the observed data.//from w w w .jav a2 s.co m * * @param manager the manager * @param genome the genome * @param populationFile the population file */ protected void processObserved(XIdObjectManager<D> manager, Genome<?> genome, File populationFile) { put(POPULATION_FILE, populationFile.toString()); put(FITNESS, genome.getFitness()); XId parent1Id = genome.getAttribute(Genome.PARENT1_ID); XId parent2Id = genome.getAttribute(Genome.PARENT2_ID); if (parent1Id != null) { put(PARENT1, genome.getAttribute(Genome.PARENT1_ID).toString()); GenealogyData<D> parent1Data = manager.getObject(getParent1Id()); if (parent1Data != null) { parent1Data.addChildren(manager, getId()); } } if (parent2Id != null) { put(PARENT2, genome.getAttribute(Genome.PARENT2_ID).toString()); GenealogyData<D> parent2Data = manager.getObject(getParent2Id()); if (parent2Data != null) { parent2Data.addChildren(manager, getId()); } } put(APPLIED_OP, genome.getAttribute(Genome.APPLIED_OP_ID)); put(CHILDREN, new JSONArray()); }
From source file:edu.usc.polar.OpenNLP.java
public static void dir(String path, String[] args) { try {/*from w ww . j a v a2 s .com*/ File root = new File(path); if (root.isFile()) { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_" + jsonCount + ".json"); if (jsonFile != null) { jsonFile.write("{\"NER_OpenNLP\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!root.getName().equals((".DS_Store"))) { ApacheOpenNLP(root.getAbsolutePath(), args); counter++; } } else { File[] list = root.listFiles(); if (list == null) { return; } for (File f : list) { if (f.isDirectory()) { dir(f.getAbsolutePath(), args); System.out.println("Dir:" + f.getAbsoluteFile()); } else { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_" + jsonCount + ".json"); // System.out.print("check"+jsonArray.toJSONString()); if (jsonFile != null) { jsonFile.write("{\"NER_OpenNLP\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!f.getName().equals((".DS_Store"))) { ApacheOpenNLP(f.getAbsolutePath(), args); counter++; // add json } } } } } catch (Exception e) { e.toString(); } }
From source file:modelo.ParametrizacionManagers.AcreditacionParametros.java
/** * //ww w .ja v a 2s . c om * Llama al Delegate para obtener un cliente especifico * * @param codigo * @return * @throws Exception */ public JSONArray getAcreditacionPorLab(String lab) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarAcreditacionParametros select = new SeleccionarAcreditacionParametros(); ResultSet rset = select.getAcreditacionPorLab(lab); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray salida = 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("codigoParam", rset.getString("CODIGO_PARAM")); /*jsonObject.put("parametro", rset.getString("PARAMETRO"));*/ //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } //Se cierra el ResultSet select.desconectar(); salida.add(jsonArray); return salida; }
From source file:com.saludtec.web.UsuariosWeb.java
private JSONArray verificarSesion(HttpServletRequest request) { objArray = new JSONArray(); if (request.getSession().getAttribute("usuario") != null) { obj = new JSONObject(); obj.put("Exito", "1"); objArray.add(obj);/*from www . j a v a 2s. c om*/ } else { obj = new JSONObject(); obj.put("Error", "usuario no loegueado"); objArray.add(obj); } return objArray; }
From source file:com.piusvelte.hydra.UnidataConnection.java
@SuppressWarnings("unchecked") @Override/*from ww w .j av a2 s . c o m*/ public JSONObject execute(String statement) { JSONObject response = new JSONObject(); JSONArray errors = new JSONArray(); try { UniCommand uCommand = mSession.command(); uCommand.setCommand(statement); uCommand.exec(); String[] fmValues = uCommand.response().split(UniTokens.AT_FM, -1); JSONArray rows = new JSONArray(); for (String fmValue : fmValues) { JSONArray rowData = new JSONArray(); String[] vmValues = fmValue.split(UniTokens.AT_VM, -1); for (String vmValue : vmValues) rowData.add(vmValue); rows.add(rowData); } response.put("result", rows); } catch (UniSessionException e) { errors.add(e.getMessage()); } catch (UniCommandException e) { errors.add(e.getMessage()); } response.put("errors", errors); if (!response.containsKey("result")) { JSONArray rows = new JSONArray(); JSONArray rowData = new JSONArray(); rows.add(rowData); response.put("result", rows); } return response; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.ActionPointQuery.java
@SuppressWarnings("unchecked") public String execute(IServletConfig config, String[] parameters) { String vehicleId = parameters[3]; String apIndexString = parameters[4]; if (vehicleId == null || "".equals(vehicleId) || apIndexString == null || !apIndexString.matches("\\d+")) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " Invalid query!"); return JSONValue.toJSONString("Invalid query!"); }//w ww .j a v a 2 s . c om IVirtualVehicle vehicle = vehicleMap.get(vehicleId); if (vehicle == null) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " Vehicle not found (anymore)!"); return JSONValue.toJSONString("Vehicle not found (anymore)!"); } int actionPointIndex = Integer.valueOf(apIndexString); if (actionPointIndex > vehicle.getTaskList().size() - 1) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " No such action point!"); return JSONValue.toJSONString("No such action point!"); } JSONObject props = new JSONObject(); for (Entry<Object, Object> e : vehicle.getProperties().entrySet()) { props.put((String) e.getKey(), e.getValue()); } props.put(PROP_VEHICLE_LOCAL_NAME, vehicle.getWorkDir().getName()); if (vehicle.isProgramCorrupted()) { props.put(PROP_VEHICLE_STATE, "corrupt"); } else if (vehicle.isCompleted()) { props.put(PROP_VEHICLE_STATE, "completed"); } else if (vehicle.isActive()) { props.put(PROP_VEHICLE_STATE, "active"); } else { props.put(PROP_VEHICLE_STATE, "suspended"); } ITask cmd = vehicle.getTaskList().get(actionPointIndex); props.put(PROP_VEHICLE_ACTION_POINT, cmd.getPosition()); props.put(PROP_VEHICLE_TOLERANCE, cmd.getTolerance()); JSONArray act = new JSONArray(); for (IAction a : cmd.getActionList()) { act.add(a); } props.put(PROP_VEHICLE_ACTIONS, act); // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " " + JSONValue.toJSONString(props)); return JSONValue.toJSONString(props); }