List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:me.prokopyl.storagemonitor.httpserver.HTTPResponse.java
static public String ToJSONString(Object object) { if (object instanceof JSONAware) { return ((JSONAware) object).toJSONString(); } else {// w w w . ja v a 2s. co m JSONArray array = new JSONArray(); array.add(object); return array.toJSONString(); } }
From source file:com.aerothai.database.user.UserService.java
public JSONObject GetUserAll(String role, String opt) throws Exception { ArrayList<UserObj> feeds = new ArrayList<UserObj>(); Connection dbConn = null;/*ww w . j a va 2 s .co m*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "list"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * ," + "(SELECT dept.name FROM dept where dept.iddept=user.iddept) as shdept," + "(SELECT unit.name FROM unit where unit.idunit=user.idunit) as shunit," + "(SELECT role.name FROM role where role.idrole=user.idrole) as shrole" + " FROM user"; if (!role.equals("0")) { query = query + " WHERE idrole =" + role; if (isNotNull(opt)) query = query + " AND " + opt; } else { if (isNotNull(opt)) query = query + " WHERE " + opt; } System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("iduser", rs.getInt("iduser")); jsonData.put("name", rs.getString("name")); jsonData.put("lastname", rs.getString("lastname")); jsonData.put("idposition", rs.getInt("idposition")); jsonData.put("iddept", rs.getInt("iddept")); ; jsonData.put("idunit", rs.getInt("idunit")); jsonData.put("idrole", rs.getInt("idrole")); jsonData.put("address", rs.getString("address")); jsonData.put("email", rs.getString("email")); jsonData.put("tel", rs.getString("tel")); jsonData.put("actunit", rs.getString("actunit")); jsonData.put("username", rs.getString("username")); jsonData.put("photo", rs.getString("photo")); jsonData.put("actcust", rs.getString("actcust")); //jsonData.put("namedept",rs.getString("dept.name")); //jsonData.put("shortdept",rs.getString("shortname")); jsonData.put("shdept", rs.getString("shdept")); jsonData.put("shunit", rs.getString("shunit")); jsonData.put("shrole", rs.getString("shrole")); 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:org.kitodo.data.index.elasticsearch.type.UserGroupType.java
@SuppressWarnings("unchecked") @Override// w w w. j a v a 2 s . c o m public HttpEntity createDocument(UserGroup userGroup) { LinkedHashMap<String, String> orderedUserGroupMap = new LinkedHashMap<>(); orderedUserGroupMap.put("title", userGroup.getTitle()); orderedUserGroupMap.put("permission", userGroup.getPermission().toString()); JSONArray users = new JSONArray(); List<User> userGroupUsers = userGroup.getUsers(); for (User user : userGroupUsers) { JSONObject userObject = new JSONObject(); userObject.put("id", user.getId().toString()); users.add(userObject); } JSONObject userGroupObject = new JSONObject(orderedUserGroupMap); userGroupObject.put("users", users); return new NStringEntity(userGroupObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:botvn.libraries.StorageCookies.java
public boolean Save() { if (mCookieStore != null) { FileWriter file = null;//w w w . j ava 2 s. c om try { List<Cookie> ckss = mCookieStore.getCookies(); HashMap<String, Object> d; JSONArray allCks = new JSONArray(); for (Cookie cks : ckss) { d = new HashMap<>(ckss.size()); String name = cks.getName(); long expires = cks.getExpiryDate() != null ? cks.getExpiryDate().getTime() : 0; String path = cks.getPath(); String domain = cks.getDomain(); boolean secure = cks.isSecure(); d.put("name", name); d.put("expires", expires); d.put("path", path); d.put("domain", domain); d.put("secure", secure); allCks.add(d); } String jsonStr = allCks.toJSONString(); String currentDir = System.getProperty(USER_DIR); file = new FileWriter(currentDir + "/" + COOKIE_FILE); file.write(jsonStr); file.flush(); file.close(); return true; } catch (IOException ex) { Logger.getLogger(StorageCookies.class.getName()).log(Level.SEVERE, null, ex); } } return false; }
From source file:org.kitodo.data.index.elasticsearch.type.BatchType.java
@SuppressWarnings("unchecked") @Override/* ww w. j a va 2s. c o m*/ public HttpEntity createDocument(Batch batch) { LinkedHashMap<String, String> orderedBatchMap = new LinkedHashMap<>(); orderedBatchMap.put("title", batch.getTitle()); String type = batch.getType() != null ? batch.getType().toString() : "null"; orderedBatchMap.put("type", type); JSONArray processes = new JSONArray(); List<Process> batchProcesses = batch.getProcesses(); for (Process process : batchProcesses) { JSONObject processObject = new JSONObject(); processObject.put("id", process.getId().toString()); processes.add(processObject); } JSONObject batchObject = new JSONObject(orderedBatchMap); batchObject.put("processes", processes); return new NStringEntity(batchObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:cc.pinel.mangue.storage.StateStorage.java
public String getChapter(String mangaId) { String chapterNumber = null;// w w w. j a v a 2s . co m JSONArray jsonMangas = null; try { jsonMangas = (JSONArray) readJSON().get("mangas"); } catch (Exception e) { // ignored } if (jsonMangas == null) jsonMangas = new JSONArray(); JSONObject jsonManga = findManga(jsonMangas, mangaId); if (jsonManga != null) chapterNumber = jsonManga.get("chapterNumber").toString(); return chapterNumber; }
From source file:getPlayersRanks.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww. jav a2 s. c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); JSONArray json = new JSONArray(); DBHandler db = new DBHandler(); ArrayList<Player> players = db.getPlayers(); for (int i = 0; i < players.size(); i++) { JSONObject JSONplayer = new JSONObject(); Player player = players.get(i); JSONplayer.put("name", player.getName()); JSONplayer.put("score", player.getScore()); json.add(JSONplayer); } response.getWriter().write(json.toString()); }
From source file:Json.JsonCodes.java
public void jsonCreate(String patchName) { JSONObject obj = new JSONObject(); JSONArray ar = new JSONArray(); for (int i = 0; i < this.pageList.size(); i++) { ar.add(this.pageList.get(i)); }//from w w w . j ava2 s . c o m obj.put("patch", this.patch); obj.put("page", ar); File file = new File(patchName); try { //?, ? ?? ? if (!file.exists()) { file.createNewFile(); } //PrintWriter ? ? ? PrintWriter out = new PrintWriter(file.getAbsoluteFile()); try { //? ? out.print(obj); } finally { //? // ?? out.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:modelo.ProcesoVertimientosManagers.VerificacionInfoCaracterizacion.java
public JSONArray getVerificacionInfoCaracterizacion(Integer codigoProceso, Integer tipoInforme) throws SQLException { ResultSet rset = null;//from ww w . j a v a2 s. c om JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONArray jsonArrayPreguntas = new JSONArray(); //Se crea el objeto SeleccionarVerificacionInfoCaracterizacion select = new SeleccionarVerificacionInfoCaracterizacion( codigoProceso, tipoInforme); //Seleccionamos los "Hijos" y "Nietos" del requisito "Padre" rset = select.getVerificaciones(); while (rset.next()) { jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("reguisito", rset.getString("DESCRIPCION")); jsonObject.put("fk_informe", rset.getString("FK_TIPO_INFORME")); jsonObject.put("checkeado", rset.getString("TIENE")); jsonArray.add(jsonObject.clone()); } jsonArrayPreguntas.add(jsonArray.clone()); //Se cierra el ResultSet rset.close(); select.desconectar(); return jsonArrayPreguntas; }
From source file:modelo.ParametrizacionManagers.Tarifas.java
/** * /*from w w w . j a v a 2s . c om*/ * Obtiene la informacion de las unidades de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getTarifas() throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTarifas select = new SeleccionarTarifas(); ResultSet rset = select.getTarifas(); //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.getString("CODIGO")); jsonObject.put("valor", rset.getString("VALOR")); jsonObject.put("codParm", rset.getString("FK_PARAMFISICOQUIMICO")); jsonObject.put("descpParm", rset.getString("DESPARM")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }