List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:fr.lirmm.yamplusplus.yampponline.TestOaeiAlignment.java
@Test public void testOaeiAlignment() throws IOException, ClassNotFoundException, OWLOntologyStorageException, SAXException { String iamlRameauAlignment = FileUtils .readFileToString(new File("src/test/resources/iaml-rameau_valid_test.rdf"), "UTF-8"); boolean testExtractValid = false; YamFileHandler fileHandler = new YamFileHandler(); JSONObject parseOaeiJson = new JSONObject(); parseOaeiJson = fileHandler.parseOaeiAlignmentFormat(iamlRameauAlignment); JSONArray entities = (JSONArray) parseOaeiJson.get("entities"); // Look for a specific valid mapping to test if parsing worked for (int i = 0; i < entities.size(); i++) { JSONObject mappingJObject = (JSONObject) entities.get(i); if (mappingJObject.get("valid").equals("valid") && mappingJObject.get("entity1").equals("http://iflastandards.info/ns/unimarc/terms/mop/wdb") && mappingJObject.get("entity2").equals("http://data.bnf.fr/ark:/12148/cb12270245r")) { testExtractValid = true;//from w w w .j av a 2 s .c om break; } } //System.out.println(parseOaeiJson.toString()); assertTrue(testExtractValid); }
From source file:Activities.java
private String addData(String endpoint) { String data = null;/* w w w.j a va2 s . c o m*/ try { // Construct request payload JSONObject attrObj = new JSONObject(); attrObj.put("name", "URL"); attrObj.put("value", "http://www.nvidia.com/game-giveaway"); JSONArray attrArray = new JSONArray(); attrArray.add(attrObj); TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String dateAsISO = df.format(new Date()); // Required attributes JSONObject obj = new JSONObject(); obj.put("leadId", "1001"); obj.put("activityDate", dateAsISO); obj.put("activityTypeId", "1001"); obj.put("primaryAttributeValue", "Game Giveaway"); obj.put("attributes", attrArray); System.out.println(obj); // Make request URL url = new URL(endpoint); HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection(); urlConn.setRequestMethod("POST"); urlConn.setAllowUserInteraction(false); urlConn.setDoOutput(true); urlConn.setRequestProperty("Content-type", "application/json"); urlConn.setRequestProperty("accept", "application/json"); urlConn.connect(); OutputStream os = urlConn.getOutputStream(); os.write(obj.toJSONString().getBytes()); os.close(); // Inspect response int responseCode = urlConn.getResponseCode(); if (responseCode == 200) { System.out.println("Status: 200"); InputStream inStream = urlConn.getInputStream(); data = convertStreamToString(inStream); System.out.println(data); } else { System.out.println(responseCode); data = "Status:" + responseCode; } } catch (MalformedURLException e) { System.out.println("URL not valid."); } catch (IOException e) { System.out.println("IOException: " + e.getMessage()); e.printStackTrace(); } return data; }
From source file:cc.pinel.mangue.storage.AbstractStorage.java
/** * Clears the storage. * * @throws IOException */ public void clear() throws IOException { writeJSON(new JSONObject()); }
From source file:me.m0r13.maptools.MarkerUpdateTask.java
public void writePlayers(Player[] players) { JSONArray playersJson = new JSONArray(); for (Player player : players) { JSONObject json = new JSONObject(); Location pos = player.getLocation(); World world = player.getWorld(); json.put("username", player.getName()); json.put("x", pos.getX()); json.put("y", pos.getY()); json.put("z", pos.getZ()); json.put("world", world.getName()); json.put("dimension", world.getEnvironment().toString()); json.put("health", player.getHealth()); json.put("saturation", player.getSaturation()); json.put("food", player.getFoodLevel()); Location bed = player.getBedSpawnLocation(); if (bed == null) { json.put("bed", null); } else {//from w ww. j ava2 s . co m JSONArray bedJson = new JSONArray(); bedJson.add(bed.getBlockX()); bedJson.add(bed.getBlockY()); bedJson.add(bed.getBlockZ()); json.put("bed", bedJson); } json.put("level", (float) player.getLevel() + player.getExp()); playersJson.add(json); } JSONObject json = new JSONObject(); json.put("players", playersJson); try { File file = new File(plugin.getConfig().getString("markerFile")); BufferedWriter output = new BufferedWriter(new FileWriter(file)); output.write(json.toJSONString()); output.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:modelo.ParametrizacionManagers.Tarifas.java
/** * //ww w.j ava 2 s . co m * 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; }
From source file:controller.RetrieveSchema.java
@SuppressWarnings("unchecked") public String retrieveSchema(String _projectId) throws IOException, DatabaseException, MissingPropertiesFile, SQLException, ConnectionClosedException, DatabaseValueNotFoundException { JSONObject obj = new JSONObject(); dao = new GetSchemaDao(); Schema schema = dao.getSchema(Integer.parseInt(_projectId)); JSONArray tables = new JSONArray(); JSONArray columns = new JSONArray(); for (Table table : schema.getTables()) { tables.add(table.getName());/* ww w .j a v a 2 s. com*/ } for (Column column : schema.getColumns()) { columns.add(column.getName()); } obj.put("tables", tables); obj.put("columns", columns); return json.nestedJson(State.PASSED, obj); }
From source file:Javafile.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . j av a 2 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/json;charset=UTF-8"); //System.out.print("I am here"); try { HashMap<String, Integer> words = new HashMap<String, Integer>(); HashMap<String, String> matchedWords = new HashMap<String, String>(); readWords(words); long totalFind = 0; JSONObject wordObj = new JSONObject(); JSONArray matchedArrayJSON = new JSONArray(); String s = request.getParameter("inputStr"); int page = Integer.parseInt(request.getParameter("page")); int count; count = page * 10; totalFind = findMatchedWords(s, words, matchedWords, matchedArrayJSON, count); wordObj.put("matchedArrayJSON", matchedArrayJSON); wordObj.put("totalFind", totalFind); call_Webpage(request, response, wordObj); } finally { } }
From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java
/** * * Llama al delegate para Eliminar un Laboratorio * * @param codigo //from w w w. ja v a2 s .c om * @throws Exception */ public JSONArray Eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarTiposInformesVertimientos delete = new EliminarTiposInformesVertimientos(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:com.p000ison.dev.simpleclans2.exceptions.handling.ExceptionReport.java
public JSONObject getJSONObject() { JSONObject report = new JSONObject(); report.put("plugin", name); report.put("version", version); report.put("date", date); report.put("exception_class", thrown.getClass().getName()); report.put("message", thrown.getMessage()); report.put("exception", buildThrowableJSON(thrown)); StringBuilder plugins = new StringBuilder().append('['); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { plugins.append(plugin).append(','); }//from w w w.j av a 2 s . co m plugins.deleteCharAt(plugins.length() - 1).append(']'); report.put("plugins", plugins.toString()); report.put("bukkit_version", Bukkit.getBukkitVersion()); report.put("java_version", getProperty("java.version")); report.put("os_arch", getProperty("os.arch")); report.put("os_name", getProperty("os.name")); report.put("os_version", getProperty("os.version")); if (email != null) { report.put("email", email); } JSONArray causes = new JSONArray(); Throwable cause = thrown; while ((cause = cause.getCause()) != null) { causes.add(buildThrowableJSON(cause)); } report.put("causes", causes); return report; }
From source file:modelo.ParametrizacionManagers.TiemposBackup.java
/** * /* w w w . ja v a2 s .c o m*/ * 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 getTiemposBackup() throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiemposBackup select = new SeleccionarTiemposBackup(); ResultSet rset = select.getTiemposBackup(); //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("tiempo", rset.getString("DIAS_BACKUP")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); select.desconectar(); return jsonArreglo; }