List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.nubits.nubot.testsmanual.TestRPCLiquidityInfo.java
private void testSendLiquidityInfo(double amountBuy, double amountSell, int tier) { if (Global.rpcClient.isConnected()) { JSONObject responseObject = Global.rpcClient.submitLiquidityInfo(Global.rpcClient.USDchar, amountBuy, amountSell, tier);/*from w w w .j a v a2 s. c om*/ if (null == responseObject) { LOG.error("Something went wrong while sending liquidityinfo"); } else { LOG.info(responseObject.toJSONString()); if ((boolean) responseObject.get("submitted")) { LOG.info("Now calling getliquidityinfo"); JSONObject infoObject = Global.rpcClient.getLiquidityInfo(NuRPCClient.USDchar); LOG.info(infoObject.toJSONString()); } } } else { LOG.error("Nu Client offline. "); } }
From source file:com.nubits.nubot.tests.TestRPC.java
private void testSendLiquidityInfo(double amountBuy, double amountSell, int tier) { if (Global.rpcClient.isConnected()) { JSONObject responseObject = Global.rpcClient.submitLiquidityInfo(Global.rpcClient.USDchar, amountBuy, amountSell, tier);//from www. j a v a 2s .co m if (null == responseObject) { LOG.severe("Something went wrong while sending liquidityinfo"); } else { LOG.info(responseObject.toJSONString()); if ((boolean) responseObject.get("submitted")) { LOG.info("Now calling getliquidityinfo"); JSONObject infoObject = Global.rpcClient.getLiquidityInfo(NuRPCClient.USDchar); LOG.info(infoObject.toJSONString()); } } } else { LOG.severe("Nu Client offline. "); } }
From source file:cpd3314.project.CPD3314ProjectTest.java
private void assertJSONFilesEqual(File a, File b) throws IOException { Scanner aIn = new Scanner(a); Scanner bIn = new Scanner(b); StringBuilder aJSON = new StringBuilder(); StringBuilder bJSON = new StringBuilder(); while (aIn.hasNext() && bIn.hasNext()) { aJSON.append(aIn.nextLine().trim()); bJSON.append(bIn.nextLine().trim()); }/*from ww w. j av a2 s .c o m*/ assertTrue("Files Not Equal Length", !aIn.hasNext() && !bIn.hasNext()); JSONObject aJ = (JSONObject) JSONValue.parse(aJSON.toString()); JSONObject bJ = (JSONObject) JSONValue.parse(bJSON.toString()); assertEquals(aJ.toJSONString(), bJ.toJSONString()); }
From source file:importer.handler.post.annotate.Annotation.java
/** * Build an annotation for the database//from ww w . ja v a 2 s . co m * @param config the loaded xml->html configuration from the database * @return a JSON string */ public String toJSONString(JSONObject config) throws HTMLException { JSONObject jObj = new JSONObject(); jObj.put(JSONKeys.BODY, toHTML("<note>" + this.body + "</note>", config)); jObj.put(JSONKeys.OFFSET, offset); jObj.put(JSONKeys.LEN, length); jObj.put(JSONKeys.AUTHOR, resp); jObj.put(JSONKeys.LINK, link); return jObj.toJSONString(); }
From source file:com.opensoc.parsing.test.BasicLancopeParserTest.java
/** * Test method for {@link com.opensoc.parsing.parsers.BasicLancopeParser#parse(byte[])}. * @throws Exception //from w w w .ja v a 2s .com * @throws IOException */ public void testParse() throws IOException, Exception { for (String inputString : getInputStrings()) { JSONObject parsed = parser.parse(inputString.getBytes()); assertNotNull(parsed); System.out.println(parsed); JSONParser parser = new JSONParser(); Map<?, ?> json = null; try { json = (Map<?, ?>) parser.parse(parsed.toJSONString()); assertEquals(true, validateJsonData(super.getSchemaJsonString(), json.toString())); } catch (ParseException e) { e.printStackTrace(); } } }
From source file:com.wso2mobile.mam.packageExtractor.ZipFileReading.java
public String readiOSManifestFile(String filePath, String name) { String plist = ""; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try {// w w w . j ava 2 s .c o m File file = new File(filePath); ZipInputStream stream = new ZipInputStream(new FileInputStream(file)); try { ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { if (entry.getName().equals("Payload/" + name + ".app/Info.plist")) { InputStream is = stream; int nRead; byte[] data = new byte[16384]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); } } } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } NSDictionary rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray()); JSONObject obj = new JSONObject(); obj.put("version", rootDict.objectForKey("CFBundleVersion").toString()); obj.put("name", rootDict.objectForKey("CFBundleName").toString()); obj.put("package", rootDict.objectForKey("CFBundleIdentifier").toString()); plist = obj.toJSONString(); } catch (Exception e) { plist = "Exception occured " + e; e.printStackTrace(); } return plist; }
From source file:com.iitb.cse.Utils.java
@SuppressWarnings("unchecked") static String getServerConfiguration(String serverIP, String serverPORT, String connectionPORT) { JSONObject obj = new JSONObject(); obj.put(Constants.action, "action_changeServer"); // hbDuration if (serverIP != null && !serverIP.trim().equalsIgnoreCase("")) { obj.put("serverip", serverIP); } else {// w ww. j ava 2 s. co m obj.put("serverip", ""); } if (serverPORT != null && !serverPORT.trim().equalsIgnoreCase("")) { obj.put("serverport", serverPORT); } else { obj.put("serverport", ""); } if (connectionPORT != null && !connectionPORT.trim().equalsIgnoreCase("")) { obj.put("connectionport", connectionPORT); } else { obj.put("connectionport", ""); } String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:ch.simas.jtoggl.TimeEntry.java
public TimeEntry(String jsonString) { JSONObject object = (JSONObject) JSONValue.parse(jsonString); this.id = (Long) object.get("id"); this.description = (String) object.get("description"); this.start = DateUtil.convertStringToDate((String) object.get("start")); this.stop = DateUtil.convertStringToDate((String) object.get("stop")); this.duration = (Long) object.get("duration"); this.billable = (Boolean) object.get("billable"); this.duronly = (Boolean) object.get("duronly"); created_with = (String) object.get("created_with"); this.pid = (Long) object.get("pid"); this.wid = (Long) object.get("wid"); this.tid = (Long) object.get("tid"); JSONObject workspaceObject = (JSONObject) object.get("workspace"); if (workspaceObject != null) { this.workspace = new Workspace(workspaceObject.toJSONString()); }//from w w w . j a v a2s . com JSONObject projectObject = (JSONObject) object.get("project"); if (projectObject != null) { this.project = new Project(projectObject.toJSONString()); } // Tag names JSONArray tagsArray = (JSONArray) object.get("tags"); List<String> tags = new ArrayList<String>(); if (tagsArray != null) { for (Object arrayObject : tagsArray) { tags.add((String) arrayObject); } } this.tag_names = tags; }
From source file:com.opensoc.parsing.test.BasicIseParserTest.java
/** * Test method for//from w w w . j a va 2s .c o m * {@link com.opensoc.parsing.parsers.BasicIseParser#parse(byte[])}. * * @throws IOException * @throws Exception */ public void testParse() throws ParseException, IOException, Exception { for (String inputString : getInputStrings()) { JSONObject parsed = parser.parse(inputString.getBytes()); assertNotNull(parsed); System.out.println(parsed); JSONParser parser = new JSONParser(); Map<?, ?> json = null; try { json = (Map<?, ?>) parser.parse(parsed.toJSONString()); assertEquals(true, validateJsonData(super.getSchemaJsonString(), json.toString())); } catch (ParseException e) { e.printStackTrace(); } } }
From source file:de.minestar.sixteenblocks.Threads.JSONThread.java
@SuppressWarnings("unchecked") @Override/*w w w . java 2 s . co m*/ public void run() { // Create sync thread to use notthreadsafe methods Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() { @Override public void run() { BufferedWriter bWriter = null; try { JSONObject json = new JSONObject(); json.put("ConnectedUsers", Bukkit.getOnlinePlayers().length); json.put("Skins", aManager.getUsedAreaCount()); json.put("Slots", Core.getAllowedMaxPlayer()); bWriter = new BufferedWriter(new FileWriter(JSONFile)); bWriter.write(json.toJSONString()); bWriter.flush(); bWriter.close(); } catch (Exception e) { ConsoleUtils.printException(e, Core.NAME, "Can't save JSON"); } finally { try { if (bWriter != null) bWriter.close(); } catch (Exception e2) { // IGNORE SECOND EXCEPTION } } } }); }