List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:edu.usc.polar.OpenNLP.java
public static void ApacheOpenNLP(String doc, String args[]) { try {//from ww w . j a v a 2s .c o m String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); System.out.println("Desc:: " + metadata.get("description")); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); Map<String, Set<String>> list = tikaOpenNLP(text); System.out.println(combineSets(list)); JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " ")); JSONArray tempArray = new JSONArray(); JSONObject tempObj = new JSONObject(); for (Map.Entry<String, Set<String>> entry : list.entrySet()) { System.out.println("\"" + entry.getKey() + "/" + ":\"" + entry.getValue() + "\""); tempObj.put(entry.getKey(), entry.getValue()); // String jsonOut="{ DOI:"+name+" ," // + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\"" // + "\"metadata\":\""+metaValue+"\"" // + "}"; // System.out.println(jsonOut); // tempObj.put(item.first(),text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")); } tempArray.add(tempObj); jsonObj.put("NER", tempArray); jsonArray.add(jsonObj); // System.out.println("---"); } catch (Exception e) { System.out.println("ERROR : OpenNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:mysynopsis.SystemInitializer.java
private static void setDefault() throws IOException { JSONObject bio = new JSONObject(); bio.put("Name", ""); bio.put("Initial", ""); bio.put("Bio", "<p><font face=\"Arial\" size=\"4\"><b>Biography goes here</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>"); bio.put("Designation", ""); bio.put("Department", ""); bio.put("University", ""); bio.put("University_Address", ""); bio.put("Office", ""); bio.put("Ohours", ""); bio.put("Phone", ""); bio.put("Email", ""); bio.put("Resume_Link", ""); bio.put("Educational", "<p><font face=\"Arial\" size=\"4\"><b>Educational Information</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>"); bio.put("Professional", "<p><font face=\"Arial\" size=\"4\"><b>Professional Experience</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>"); bio.put("Awards", "<p><font face=\"Arial\" size=\"4\"><b>Awards</b></font></p><p><br></p><p></p><p><font face=\"Segoe UI\" size=\"4\"><br></font></p>"); bio.put("Image_Ext", "png"); bio.put("Image_String", "iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAKxklEQVR42u1de2wcRx0eQEAqQQVCAhFaSiv+QfwBqQoECAgJCbUChCoKCJXm2QYngdA0Aadp1IY4zbNJaePWcR7Ow44fiRO/HdmxYyf3ct2QPpI4e3uk0JBU/EMLTbx7O7vsMt+2xCFOfA/v7s3szk/65Lvz3t3sfDczv9f8hoRBXhqxP5XKmN9LpK35CdVcm1RpA3s8kExbp9njt+IK/XdSoTr7+x8Aj/Ga+z/Veh3Xssf1eG88bT2Cz8JnEinBS7dqfzSept9JqNbyhGK1M2IuJVXL8QNxlV5k5Lex7ypPKXQGvptI8V7i5+yprJMXJhWrg4280VzE+Ej4FfyoUqq14PiI/VkipXiJvel80iVVtU4wUm10ME9Am+KKNcgelw381fkEkZJbHMf5QCJDv5VM031YJ7khNDfZGhvde2MqnU6kjJcDjvOhZMb6GRuxQ+gwoaFYybhq/hT3RKIubMR+MKVYv0iq5jl0TpiQUMyzTCt/APdIoiisA77PTJTX0Bkhxyswu0hUZEix72Q33cLgRAqK1Zx4w74j3Ousai0ZM3OiB9fMSluLQ7c+JzP2F/+nQEm8p4jF0s5d4TB7VG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U7FRN68lkJfGGfUcxseJl9XJqLsD7VdxJ4Kp9G/FAkLO1uEB/cuRJKxAF28gI73p6xHshzo/KXrn2FgiUayzIqeGaRV5KLO3chVOn82nA2jZp8xYIxLnzTsfBskl8ENTUmplPI55okuuvT9Xz4NP+JfFLYG8hYjFxI6TtWwTQZ7nJVcwq4rMgZjwFp05LgoMlGCfCIvuVBCHDGft2lH6QBAdDMLYW4eAyEqQkM8bdsI8lwX4TTC/H0sZXSCkkpZj3MZKpJNgfgtG3cdX8ASmlJFTzAaRqSoI9JlihFlNo7yc8CGvQgyBZEuwNwSDXNYd4EmSBYEqRBE+KYEzLBjcjd7ziZd4LxUsSXCzB9LK75vIsCdWY9niDlo06YYWivFHTXW1ZBHlx0Jj2WK12Oeqk5YtHa7V3n+0xvkpEkueG7FtXHNRGok5eLqw8oJ2uHHA+RkSV9e3G8/OqR+2oE3k9Ht4+am/sMraQMMifuukMNmX/K+qkvg9ku7y9uZdOJ2ESJA1UtOhN86qv2FEetRWt+n43WB9W2dpL7ynfr1+IoBn0t8oBKFIRkWe69EW/q9WuhJ3YJfu0y1s69fkkioIEgnWt+vrFezU9bMQu3qNpGzr0NbhHEnXB+ry+XX96SQgUsaV12jsb2vXV7jorZbw806nPXtmkpedWjwpD6rzto86KRk3ZcsR4iEjJT57rtm9b00L3MPPq7VkcbjlFm5bVav9c10ZrtvbaU4mU4oWNjC+zk1D2lDdkL5XSzMJ3lzfol0DqC53ZLxEp3ktT0r5lc7c+b/VhrbO8Ub+0YOcVy7/qOaPmH+qzFyuatY5NXfqc3QPOFCIleNnUo9+5sUNfUNGa3b2qWY+taBw9j6n9t0yTxQ8ADoa51e606gKP8Rr+h2twLd6D965ho3NTOy1bd0T/AgmB/Bd/W0C3K+5ULAAAAABJRU5ErkJggg=="); // JSONArray education = new JSONArray(); /*for(int i=0;i<8;i++) { /*from w ww .j a v a 2 s . c o m*/ education.add(""); } bio.put("Education", education);*/ JSONArray ftpinfo = new JSONArray(); ftpinfo.add(""); ftpinfo.add(""); ftpinfo.add(""); bio.put("Server_Information", ftpinfo); /* JSONArray professional = new JSONArray(); professional.add("Profession 1: "); professional.add("Profession 2: "); bio.put("Professional Experience:", professional); JSONArray awards = new JSONArray(); awards.add("Award 1: "); awards.add("Award 2: "); bio.put("Honors & Awards:", awards);*/ try (FileWriter file = new FileWriter("data.json")) { file.write(bio.toJSONString()); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Can't Create Data.json File. Please Check Your Directory Permission"); } }
From source file:javaphpmysql.JavaPHPMySQL.java
public static void sendGet() { //Creamos un objeto JSON JSONObject jsonObj = new JSONObject(); //Aadimos el nombre, apellidos y email del usuario jsonObj.put("nombre", nombre); jsonObj.put("apellidos", apellidos); jsonObj.put("email", email); //Creamos una lista para almacenar el JSON List l = new LinkedList(); l.addAll(Arrays.asList(jsonObj)); //Generamos el String JSON String jsonString = JSONValue.toJSONString(l); System.out.println("JSON GENERADO:"); System.out.println(jsonString); System.out.println(""); try {/* w w w.j ava 2s .c o m*/ //Codificar el json a URL jsonString = URLEncoder.encode(jsonString, "UTF-8"); //Generar la URL String url = SERVER_PATH + "listenGet.php?json=" + jsonString; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("GET"); //add request header con.setRequestProperty("User-Agent", USER_AGENT); int responseCode = con.getResponseCode(); System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //print result System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.punyal.blackhole.utils.Parsers.java
public static JSONObject senml2json(String s) { JSONObject json, tmp; String data;/* w w w. ja v a2 s . c o m*/ json = new JSONObject(); try { tmp = (JSONObject) JSONValue.parse(s); // Save base time json.put("time", tmp.get("bt")); JSONArray slideContent = (JSONArray) tmp.get("e"); Iterator i = slideContent.iterator(); while (i.hasNext()) { JSONObject slide = (JSONObject) i.next(); json.put(slide.get("n"), slide.get("v")); } } catch (NullPointerException e) { } return json; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void obtenerTotalUsuarios(HttpServletRequest request, HttpServletResponse response) throws IOException { int numC = CtrlAdmin.obtenerTotalUsuarios(); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("total", numC); out.print(obj);/*from ww w. ja va2s. c om*/ }
From source file:javaphpmysql.JavaPHPMySQL.java
public static void sendPost() { //Creamos un objeto JSON JSONObject jsonObj = new JSONObject(); //Aadimos el nombre, apellidos y email del usuario jsonObj.put("nombre", nombre); jsonObj.put("apellidos", apellidos); jsonObj.put("email", email); //Creamos una lista para almacenar el JSON List l = new LinkedList(); l.addAll(Arrays.asList(jsonObj)); //Generamos el String JSON String jsonString = JSONValue.toJSONString(l); System.out.println("JSON GENERADO:"); System.out.println(jsonString); System.out.println(""); try {//from ww w.ja v a 2s .c om //Codificar el json a URL jsonString = URLEncoder.encode(jsonString, "UTF-8"); //Generar la URL String url = SERVER_PATH + "listenPost.php"; //Creamos un nuevo objeto URL con la url donde queremos enviar el JSON URL obj = new URL(url); //Creamos un objeto de conexin HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //Aadimos la cabecera con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); //Creamos los parametros para enviar String urlParameters = "json=" + jsonString; // Enviamos los datos por POST con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); //Capturamos la respuesta del servidor int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } //Mostramos la respuesta del servidor por consola System.out.println(response); //cerramos la conexin in.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuario(request.getParameter("1")); // String nombre del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", e.getRol()); out.print(obj);//from w w w. j a v a 2 s . co m }
From source file:hoot.services.review.ReviewItemsPreparer.java
/** * Launches a review prepare job in a separate thread * * @param mapId ID of the map for which to launch the prepare job * @param testDelayMilliseconds a pause time in milliseconds for testing purposes * @param simulateFailure if true; forces the prepare job to throw an exception after it * completes; for testing purposes/*from w ww .j a v a 2 s . c o m*/ * @param writer the review record writer to use * @return a trackable job ID */ @SuppressWarnings("unchecked") public static String launchPrepareJob(final long mapId, final long testDelayMilliseconds, final boolean simulateFailure, final String writer) { log.debug("Launching review prepare job for map with ID: " + String.valueOf(mapId) + " ..."); JSONObject command = new JSONObject(); command.put("mapId", mapId); command.put("execImpl", writer); if (testDelayMilliseconds > 0) { command.put("testDelayMilliseconds", testDelayMilliseconds); } if (simulateFailure) { command.put("simulateFailure", true); } final String jobId = UUID.randomUUID().toString(); (new JobExecutioner(jobId, command)).start(); return jobId; }
From source file:net.duckling.ddl.util.StringUtil.java
License:asdf
@SuppressWarnings({ "deprecation" }) public static boolean illTitle(HttpServletResponse resp, String title) { if (StringUtils.isNotEmpty(title) && pattern.matcher(title).find()) { if (resp != null) { JSONObject obj = new JSONObject(); obj.put("success", false); obj.put("result", false); obj.put("error", "??<>:\"|*?/\\"); JsonUtil.writeJSONObject(resp, obj); }//ww w . j a v a2s . c o m return true; } return false; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuarioId(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuarioId(Integer.parseInt(request.getParameter("1"))); // id del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", "" + e.getRol()); obj.put("email", e.getUsername()); out.print(obj);/* www . java 2 s. co m*/ }