List of usage examples for org.json.simple JSONObject toString
@Override
public String toString()
From source file:socket.DatosPersonales.java
public static String obtenerDB(String datoRecibido) throws SQLException { String servidor = "jdbc:mysql://localhost/sd_directorio_db"; Connection miConexion = ConnectionDB.GetConnection(servidor); System.out.println(miConexion); JSONObject objJson = new JSONObject(); if (miConexion != null) { String cedula = datoRecibido; System.out.println("cedula = " + cedula); double dato = Double.valueOf(cedula); Statement s = miConexion.createStatement(); ResultSet rs = s.executeQuery("select * from datos_personales where cedula = " + dato); boolean isRecord = false; while (rs.next()) { objJson.put("Nombre", rs.getString("nombre")); objJson.put("Apellido", rs.getString("apellido")); objJson.put("CodigoSalud", rs.getString("codigo_salud")); isRecord = true;// w ww . ja v a2 s. c o m } if (!isRecord) { objJson.put("Nombre", ""); objJson.put("Apellido", ""); objJson.put("CodigoSalud", ""); } } System.out.println(objJson.toString()); String datosPersonales = objJson.toString(); return datosPersonales; }
From source file:socket.DatosSeguro.java
public static String obtenerDB(String datoRecibido) throws SQLException { String servidor = "jdbc:mysql://localhost/sd_salud_db"; Connection miConexion = ConnectionDB.GetConnection(servidor); System.out.println(miConexion); JSONObject objJson = new JSONObject(); if (miConexion != null) { String codigoSalud = datoRecibido; System.out.println("Codigo Salud = " + codigoSalud); double dato = Double.valueOf(codigoSalud); Statement s = miConexion.createStatement(); ResultSet rs = s.executeQuery("select * from datos_seguro where codigo_salud = " + dato); boolean isRecord = false; while (rs.next()) { objJson.put("Estado", rs.getString("estado")); objJson.put("SeguroSalud", rs.getString("seguro")); objJson.put("Duracion", rs.getString("duracion")); isRecord = true;/*from w ww. j av a2 s. com*/ System.out.println("IsRecord: " + isRecord); } if (!isRecord) { objJson.put("Estado", "noExiste"); objJson.put("SeguroSalud", "--"); objJson.put("Duracion", "--"); System.out.println("IsRecord: " + isRecord); } } System.out.println(objJson.toString()); String datosPersonales = objJson.toString(); return datosPersonales; }
From source file:tests.TCPTestTwo.java
String getJSONString(String command, String tag, String cargo, boolean isRead, Long id) { Map<String, Object> m = new HashMap<String, Object>(); m.put(ITupleFields.COMMAND, command); m.put(ITupleFields.TAG, tag);/*from w w w . j a v a 2 s .c om*/ m.put(ITupleFields.CARGO, cargo); if (isRead) m.put(ITupleFields.AGENT_NAME, "TCPTestTwo"); m.put(ITupleFields.ID, id); JSONObject j = new JSONObject(m); return j.toString(); //+"\n" }
From source file:tilt.image.page.Page.java
/** * Compose the shape information as GeoJson * @param pageWidth the width of the "page" (maybe a part of the image) * @param pageHeight the height of the "page" * @return the GeoJson//from w ww. j a va 2 s. co m */ public String toGeoJson(int pageWidth, int pageHeight) { JSONObject image = new JSONObject(); image.put("type", "FeatureCollection"); JSONArray bounds = new JSONArray(); // assume one bounding box for now, without rotation bounds.add(new Double(0.0)); bounds.add(new Double(0.0)); bounds.add(new Double(1.0)); bounds.add(new Double(1.0)); image.put("bbox", bounds); JSONArray features = new JSONArray(); for (int i = 0; i < lines.size(); i++) { Line l = lines.get(i); features.add(l.toGeoJSON(pageWidth, pageHeight)); } image.put("features", features); return image.toString(); }
From source file:token.ValidateToken.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject arrayObj = new JSONObject(); String str_token = request.getParameter("access_token"); String user_agent = request.getHeader("user-agent"); String ip_address = request.getRemoteAddr(); String access_token = str_token + "#" + user_agent + "#" + ip_address; String query = "SELECT * FROM tokendata WHERE token='" + access_token + "'"; System.out.println("Client USER_AGENT: " + user_agent); System.out.println("Client IP_ADDRESS: " + ip_address); try {//from ww w . j a v a2s .c o m Connection currentCon = ConnectionManager.getConnection(); Statement stmt = currentCon.createStatement(); ResultSet rs = stmt.executeQuery(query); boolean valid = rs.next(); System.out.println("ADA TOKEN TAU GAK = " + valid); if (valid) { Timestamp create_time = getTimeStamp(access_token); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(create_time.getTime()); cal.add(Calendar.MINUTE, 30); Timestamp expired_time = new Timestamp(cal.getTimeInMillis()); Timestamp current_time = new Timestamp(System.currentTimeMillis()); if (expired_time.before(current_time)) { arrayObj.put("status", "expired"); } else { arrayObj = getJsonObj(access_token); setCreateTime(getUserID(access_token), access_token, current_time); } } else { arrayObj.put("status", "non-valid"); } } catch (SQLException se) { System.out.println(se); } response.setContentType("application/json:charset=UTF-8"); response.getWriter().write(arrayObj.toString()); }
From source file:tvhchgen.Service.java
public void write() { try {// ww w . j a v a 2 s .com File file = new File(id); if (file.exists()) { file.delete(); } file.createNewFile(); JSONObject jsonObject = new JSONObject(); jsonObject.put("number", this.number); jsonObject.put("dvr_pre_time", this.preTime); jsonObject.put("dvr_pst_time", this.postTime); if (!icon.isEmpty()) { jsonObject.put("icon", this.icon); } jsonObject.put("services", this.services); jsonObject.put("tags", this.tags); FileWriter fw = new FileWriter(file); String jsonStr = jsonObject.toString(); jsonStr = jsonStr.replace("{", "{\n\t"); jsonStr = jsonStr.replace(",\"", ",\n\t\""); jsonStr = jsonStr.replace("}", "\n}"); fw.write(jsonStr); //System.out.println( jsonStr ); fw.flush(); fw.close(); } catch (Exception e) { System.out.println("Exception: " + e.toString()); } }
From source file:tvhchgen.Service.java
/** * /*from www. ja va 2 s . com*/ * @param filePath */ public void write(String filePath) { try { File file = new File(filePath); if (file.exists()) { file.delete(); } file.createNewFile(); JSONObject jsonObject = new JSONObject(); jsonObject.put("enabled", this.enabled); jsonObject.put("internal", this.internal); jsonObject.put("titledIcon", this.titledIcon); jsonObject.put("name", this.name); jsonObject.put("comment", this.comment); jsonObject.put("id", this.id); FileWriter fw = new FileWriter(file); String jsonStr = jsonObject.toString(); jsonStr = jsonStr.replace("{", "{\n\t"); jsonStr = jsonStr.replace(",\"", ",\n\t\""); jsonStr = jsonStr.replace("}", "\n}"); fw.write(jsonStr); //System.out.println( jsonStr ); fw.flush(); fw.close(); } catch (Exception e) { System.out.println("Exception: " + e.toString()); } }
From source file:uk.co.everywheremusic.model.RestApi.java
/** * * @param request/*from ww w . jav a 2s .c o m*/ * @param response * @throws ServletException * @throws IOException */ public void handleTimeRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean auth = false; if (queryString != null) { String[] args = queryString.split(Pattern.quote("&")); if (args != null && args.length == 1) { String[] keyValueOne = args[0].split(Pattern.quote("=")); if (keyValueOne != null && keyValueOne.length == 2) { if (keyValueOne[0].equals("auth")) { DBManager dbm = new DBManager(installFolder); PasswordDAO pdao = dbm.getPasswordDAO(); auth = pdao.authenticatePassword(keyValueOne[1]); } } } } if (auth) { JSONObject objTime = new JSONObject(); objTime.put("ServerTimestamp", System.currentTimeMillis()); String result = objTime.toString(); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(result); } else { response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.getWriter().println("<h1>Error 401: Forbidden</h1>"); } }