List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.iitb.cse.Utils.java
/** * genetated and returns the String in Json format. String contains * information that the experiment has been stopped by experimenter This * string is later sent to filtered devices. *///from w ww . j a v a 2 s.c o m @SuppressWarnings("unchecked") static String getLogFilesJson(int expID) { JSONObject obj = new JSONObject(); //{action:getLogFile} obj.put(Constants.action, Constants.getLogFiles); obj.put(Constants.expID, Integer.toString(expID)); String jsonString = obj.toJSONString(); System.out.println(jsonString); return jsonString; }
From source file:module.entities.NameFinder.DB.java
/** * Update the activity log// w ww. j a va 2 s. c o m * * @param endTime * @param status_id * @param regexerId * @param obj * @throws java.sql.SQLException */ public static void UpdateLogRegexFinder(long endTime, int regexerId, JSONObject obj) throws SQLException { String updateCrawlerStatusSql = "UPDATE log.activities SET " + "end_date = ?, status_id = ?, message = ?" + "WHERE id = ?"; PreparedStatement prepUpdStatusSt = connection.prepareStatement(updateCrawlerStatusSql); prepUpdStatusSt.setTimestamp(1, new java.sql.Timestamp(endTime)); prepUpdStatusSt.setInt(2, 2); prepUpdStatusSt.setString(3, obj.toJSONString()); prepUpdStatusSt.setInt(4, regexerId); prepUpdStatusSt.executeUpdate(); prepUpdStatusSt.close(); }
From source file:de.sub.goobi.forms.IndexingForm.java
private static String readMapping() throws ParseException { JSONParser parser = new JSONParser(); ClassLoader classloader = Thread.currentThread().getContextClassLoader(); try (InputStream inputStream = classloader.getResourceAsStream("mapping.json")) { String mapping = IOUtils.toString(inputStream, "UTF-8"); Object object = parser.parse(mapping); JSONObject jsonObject = (JSONObject) object; return jsonObject.toJSONString(); } catch (IOException e) { logger.error(e);// w w w .j av a2 s .c o m return ""; } }
From source file:com.fujitsu.dc.test.utils.UserDataUtils.java
/** * ??????./*from w ww .j a va 2 s. co m*/ * @param token * @param code ?? * @param body * @param cell ?? * @param box ?? * @param collection ?? * @param entityType * @return ? */ public static TResponse create(String token, int code, JSONObject body, String cell, String box, String collection, String entityType) { return create(token, code, body.toJSONString(), cell, box, collection, entityType); }
From source file:ch.newscron.encryption.Encryption.java
/** * Computes the max number of available characters, considering the initial URL, base64, AES, MD5 hash and JSON object. * !! Available characters do not include the follow special characters (which require > 1 bytes): "/", "\", """, "'" and any kind of accents!! * @param initialURL ("http://domain/path") * @return the max number of available characters for the four fields (customerID, reward1, reward2, validity) *//*from w w w.ja v a2 s .co m*/ public static Integer availableParameterLength(String initialURL) { try { JSONObject emptyData = new JSONObject(); emptyData.put("custID", ""); emptyData.put("rew1", ""); emptyData.put("rew2", ""); emptyData.put("val", ""); emptyData.put("hash", ""); //Max size of URL for Internet Explorer... :-( int maxURLSize = 2000; //Remove size of initial url (host+domain) maxURLSize -= initialURL.getBytes("UTF-8").length; //Base64 ratio of 3/4 maxURLSize = (int) Math.ceil((maxURLSize * 3) / 4); //Maximum number of blocks available * 16 maxURLSize = (int) Math.floor(maxURLSize / 16) * 16; //Remove size of hash (16 bytes) and empty JSON (without fields) maxURLSize -= (16 + emptyData.toJSONString().getBytes("UTF-8").length); //Remaining number of characters available return maxURLSize; } catch (Exception e) { } return null; }
From source file:it.polimi.geinterface.network.MessageUtils.java
/** * Method that builds a {@link MessageType#CHECK_IN} message relative to the passed {@link Entity} *//*w w w .java 2 s . c o m*/ public static String buildCheckInMessage(Entity e, String logId) { JSONObject mesg = new JSONObject(); JSONObject checkInMsg = new JSONObject(); checkInMsg.put(JsonStrings.SENDER, e.getEntityID()); checkInMsg.put(JsonStrings.MSG_TYPE, MessageType.CHECK_IN.name()); checkInMsg.put(JsonStrings.ENTITY, ((JSONObject) e.getJsonDescriptor().get(JsonStrings.ENTITY))); checkInMsg.put(JsonStrings.LOG_ID, logId); mesg.put(JsonStrings.MESSAGE, checkInMsg); return mesg.toJSONString(); }
From source file:it.polimi.geinterface.network.MessageUtils.java
/** * Method that builds a {@link MessageType#CHECK_OUT} message relative to the passed {@link Entity} *///from w w w . j av a 2 s .c o m public static String buildCheckOutMessage(Entity e, boolean isValid) { JSONObject mesg = new JSONObject(); JSONObject checkOutMsg = new JSONObject(); checkOutMsg.put(JsonStrings.SENDER, e.getEntityID()); checkOutMsg.put(JsonStrings.MSG_TYPE, MessageType.CHECK_OUT.name()); checkOutMsg.put(JsonStrings.ENTITY, ((JSONObject) e.getJsonDescriptor().get(JsonStrings.ENTITY))); checkOutMsg.put(JsonStrings.VALID, isValid); mesg.put(JsonStrings.MESSAGE, checkOutMsg); return mesg.toJSONString(); }
From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java
/** * ComplexTypeProperty?./*from w w w . j a v a 2 s.com*/ * @param cell ?? * @param box ?? * @param collection ?? * @param srcComplexTypePropertyName ?ComplexTypeProperty?? * @param srcComplexTypeName ?ComplexType?? * @param complexTypePropertyName ??ComplexTypeProperty?? * @param complexTypeName ??ComplexType?? * @param type Property?Type * @param nullable Property?Nullable * @param defaultValue Property?DefaultValue * @param collectionKind Property?collectionKind * @return ? */ @SuppressWarnings("unchecked") public static DcResponse create(String cell, String box, String collection, String srcComplexTypePropertyName, String srcComplexTypeName, String complexTypePropertyName, String complexTypeName, String type, Boolean nullable, Object defaultValue, String collectionKind) { // ??? JSONObject body = new JSONObject(); body.put("Name", complexTypePropertyName); body.put("_ComplexType.Name", complexTypeName); body.put("Type", type); body.put("Nullable", nullable); body.put("DefaultValue", defaultValue); body.put("CollectionKind", collectionKind); // DcRequest req = DcRequest.post(UrlUtils.complexTypeProperty(cell, box, collection, null, null)); req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN); req.addStringBody(body.toJSONString()); // return AbstractCase.request(req); }
From source file:com.codelanx.codelanxlib.logging.Debugger.java
/** * Sends a JSON payload to a URL specified by the string parameter * //from w w w .j a v a 2 s. co m * @since 0.1.0 * @version 0.1.0 * * @param url The URL to report to * @param payload The JSON payload to send via POST * @throws IOException If the sending failed */ private static void send(String url, JSONObject payload) throws IOException { URL loc = new URL(url); HttpURLConnection http = (HttpURLConnection) loc.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/json"); http.setUseCaches(false); http.setDoOutput(true); try (DataOutputStream wr = new DataOutputStream(http.getOutputStream())) { wr.writeBytes(payload.toJSONString()); wr.flush(); } }
From source file:com.fujitsu.dc.test.utils.RoleUtils.java
/** * NP?Role??.//from ww w.ja v a2 s . c om * @param cellName ?? * @param authorization Authorization?(auth-schema?) * @param srcEntityName ??? * @param srcEntityKeyString ?"Name='xxx'" * @param roleName ?? * @param code ? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaNPWithAuthSchema(final String cellName, final String authorization, final String srcEntityName, final String srcEntityKeyString, final String roleName, final int code) { JSONObject body = new JSONObject(); body.put("Name", roleName); String key = srcEntityKeyString; if (srcEntityKeyString != null && !srcEntityKeyString.contains("'")) { key = "'" + srcEntityKeyString + "'"; } return Http.request("cell/createNPWithoutQuote.txt").with("method", HttpMethod.POST) .with("token", authorization).with("cell", cellName).with("entityType", srcEntityName) .with("id", key).with("navPropName", "_Role").with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("body", body.toJSONString()).returns() .statusCode(code); }