List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:dimensionsorter.DimensionSorter.java
private static void initializeImageSorter() { try {//from w w w . ja va2 s .c o m // Retrieve storage account from connection-string // (The storage connection string needs to be changed in case of // cloud infrastructure // is used instead of emulator) CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); // Create the queue client CloudQueueClient queueClient = storageAccount.createCloudQueueClient(); // Retrieve a reference to a queue CloudQueue queue = queueClient.getQueueReference(globalImageSorterQueue); // Create the queue if it doesn't already exist queue.createIfNotExist(); // Create the json object with the appropriate variables JSONObject obj = new JSONObject(); obj.put("dataset", datasetName); obj.put("numOfL", new Integer(numberOfImageSorterNodes)); obj.put("numOfImages", new Integer(numOfImages)); // Send the Message CloudQueueMessage message = new CloudQueueMessage(obj.toJSONString()); queue.addMessage(message); } catch (InvalidKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (StorageException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.cloudera.hoop.fs.FSUtils.java
/** * Converts an object into a Json Map with with one key-value entry. * <p/>/*from www . ja v a2 s. co m*/ * It assumes the given value is either a JSON primitive type or a * <code>JsonAware</code> instance. * * @param name name for the key of the entry. * @param value for the value of the entry. * @return the JSON representation of the key-value pair. */ @SuppressWarnings("unchecked") public static JSONObject toJSON(String name, Object value) { JSONObject json = new JSONObject(); json.put(name, value); return json; }
From source file:com.oic.connection.Connections.java
/** * ??? ??/*from w w w. j a v a2 s .c o m*/ */ public static synchronized void checkLive() { new Thread(new Runnable() { @Override public void run() { while (true) { JSONObject json = new JSONObject(); json.put("method", "live"); json.put("status", 0); broadCastMessage(json); try { Thread.sleep(20000); } catch (InterruptedException ex) { } } } }).start(); }
From source file:com.telefonica.iot.cygnus.utils.CommonUtilsForTests.java
/** * Creates a JSONObject-like notification. * @return A JSONObject-like notification *//*from ww w.j a v a2 s . c o m*/ public static JSONObject createNotification() { JSONObject attribute = new JSONObject(); attribute.put("name", "temperature"); attribute.put("type", "centigrade"); attribute.put("value", "26.5"); JSONArray attributes = new JSONArray(); attributes.add(attribute); JSONObject contextElement = new JSONObject(); contextElement.put("attributes", attributes); contextElement.put("type", "Room"); contextElement.put("isPattern", "false"); contextElement.put("id", "room1"); JSONObject statusCode = new JSONObject(); statusCode.put("code", "200"); statusCode.put("reasonPhrase", "OK"); JSONObject contextResponse = new JSONObject(); contextResponse.put("contextElement", contextElement); contextResponse.put("statusCode", statusCode); JSONArray contextResponses = new JSONArray(); contextResponses.add(contextResponse); JSONObject notification = new JSONObject(); notification.put("subscriptionId", "51c0ac9ed714fb3b37d7d5a8"); notification.put("originator", "localhost"); notification.put("contextResponses", contextResponses); return notification; }
From source file:de.tuttas.websockets.ChatServer.java
public static void send(JSONObject msg, Session myself) { Log.d("Sende " + msg.toJSONString()); msg.put("msg", StringUtil.escapeHtml((String) msg.get("msg"))); for (Session s : sessions) { if (s != myself) { try { s.getBasicRemote().sendText(msg.toJSONString()); } catch (IOException ex) { Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace();/*from w w w .j a v a 2 s . c om*/ } } } }
From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java
private static JSONObject processMultiLevelRequirementsElement(MultiLevelRequirements multiLevelRequirements) { JSONObject rootJSON = new JSONObject(); rootJSON.put("name", multiLevelRequirements.getName()); rootJSON.put("level", multiLevelRequirements.getLevel().toString()); rootJSON.put("type", "RequirementsLevel"); JSONArray requirementsBlocksArray = new JSONArray(); for (Requirements r : multiLevelRequirements.getUnitRequirements()) { JSONObject requirementsJSON = new JSONObject(); requirementsJSON.put("name", r.getName()); requirementsJSON.put("target", r.getTargetServiceID()); requirementsJSON.put("type", "RequirementsBlock"); JSONArray requirementsBlockRequirements = new JSONArray(); for (Requirement requirement : r.getRequirements()) { JSONObject requirementJSON = new JSONObject(); requirementJSON.put("type", "Requirement"); JSONArray conditionsArray = new JSONArray(); Metric metric = requirement.getMetric(); requirementJSON.put("metric", metric.getName() + "[" + metric.getMeasurementUnit() + "]"); for (Condition condition : requirement.getConditions()) { JSONObject conditionJSON = new JSONObject(); conditionJSON.put("name", condition.toString()); conditionJSON.put("type", "Condition"); conditionsArray.add(conditionJSON); }/*w ww.j av a 2 s .c om*/ requirementJSON.put("target", r.getTargetServiceID()); requirementJSON.put("children", conditionsArray); requirementsBlockRequirements.add(requirementJSON); } requirementsJSON.put("children", requirementsBlockRequirements); requirementsBlocksArray.add(requirementsJSON); } rootJSON.put("children", requirementsBlocksArray); return rootJSON; }
From source file:co.alligo.toasted.routes.ServerList.java
public static String serverList(Request req, Response res, Servers servers) { JSONObject response = new JSONObject(); JSONObject result = new JSONObject(); res.header("Content-Type", "application/json"); response.put("listVersion", 1); result.put("code", 0); result.put("msg", "OK"); result.put("servers", servers.getServers()); response.put("result", result); return (String) response.toJSONString(); }
From source file:ch.newscron.shortUrlUtils.ShortenerURL.java
/** * Given a long original URL, the function makes a request to the Google API (with key) and takes out the shortened goo.gl URL from the received JsonNode. * @param longURL is the full (domain/path/ENCODED_DATA) URL created for inviting potential members * @return a String which is the goo.gl shortened URL correlated to the original long URL. */// w ww . ja v a 2s . co m public static String getShortURL(String longURL) { try { JSONObject data = new JSONObject(); data.put("longUrl", longURL); // HTTP request with the result HttpResponse<com.mashape.unirest.http.JsonNode> postResponse = Unirest.post(google_url) .header("Content-Type", "application/json").body(data.toJSONString()).asJson(); return (String) postResponse.getBody().getObject().get("id"); //If everything is working, then return the shortened URL } catch (Exception e) { } return null; //In case of errors or problems, just return the full and long URL }
From source file:msuresh.raftdistdb.RaftCluster.java
public static void createDefaultGlobal() throws IOException { JSONObject obj = new JSONObject(); obj.put("currentCount", 5000); try (FileWriter file = new FileWriter(Constants.STATE_LOCATION + "global.info")) { file.write(obj.toJSONString());/*from w w w. jav a 2 s . c o m*/ } }
From source file:cloudclient.Client.java
@SuppressWarnings("unchecked") public static void batchSendTask(PrintWriter out, String workload) throws FileNotFoundException, MalformedURLException { FileInputStream input = new FileInputStream(workload); BufferedReader bin = new BufferedReader(new InputStreamReader(input)); // Get task from workload file String line;//from w w w . java 2 s . c om // String sleepLength; String id; int count = 0; final int batchSize = 10; try { //Get client public IP String ip = getIP(); //System.out.println(ip); //JSON object Array JSONArray taskList = new JSONArray(); while ((line = bin.readLine()) != null) { //sleepLength = line.replaceAll("[^0-9]", ""); //System.out.println(sleepLength); count++; id = ip + ":" + count; JSONObject task = new JSONObject(); task.put("task_id", id); task.put("task", line); taskList.add(task); if (taskList.size() == batchSize) { out.println(taskList.toString()); taskList.clear(); } } //System.out.println(taskList.toString()); if (!taskList.isEmpty()) { out.println(taskList.toString()); taskList.clear(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }