List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:backtype.storm.multilang.JsonSerializer.java
private void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
From source file:com.treasure_data.td_import.writer.JSONRecordWriter.java
public String toJSONString() { return JSONValue.toJSONString(getRecord()); }
From source file:ch.uzh.ddis.thesis.lambda_architecture.speed.spout.kafka.ZkState.java
public void writeJSON(String path, Map<Object, Object> data) { LOG.debug("Writing " + path + " the data " + data.toString()); writeBytes(path, JSONValue.toJSONString(data).getBytes(Charset.forName("UTF-8"))); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.json.VirtualVehicleQuery.java
@Override public String execute(IServletConfig config, String[] parameters) { if (mapperProxy.getEngineInfoList() == null) { return ""; }/*from w w w . j a v a2s . com*/ // TODO do this in parallel Map<String, Object> vehicleStatus = new LinkedHashMap<String, Object>(); int pilotNumber = 0; for (EngineInfo engineInfo : mapperProxy.getEngineInfoList()) { String vehicleStatusString = null; String pilot = String.format(Locale.US, "pilot%03d", ++pilotNumber); try { String pilotName = engineInfo.getPilotName(); String vehicleStatusURL = engineInfo.getVehicleStatusUrl(); if (pilotName != null && vehicleStatusURL != null) { vehicleStatusString = HttpQueryUtils.simpleQuery(vehicleStatusURL); Map<String, Object> p = new LinkedHashMap<String, Object>(); p.put("name", pilotName); p.put("engine", engineInfo.getActionPointUrl()); p.put("vehicleData", engineInfo.getVehicleDataUrl()); p.put("vehicles", parser.parse(vehicleStatusString)); vehicleStatus.put(pilot, p); } } catch (Exception e) { LOG.info("Can not query pilot " + pilot + ": " + vehicleStatusString, e); } } return JSONValue.toJSONString(vehicleStatus); }
From source file:consumer.kafka.ZkState.java
public void writeJSON(String path, Map<Object, Object> data) { LOG.info("Writing " + path + " the data " + data.toString()); writeBytes(path, JSONValue.toJSONString(data).getBytes(Charset.forName("UTF-8"))); }
From source file:com.yahoo.storm.yarn.StormMasterCommand.java
@Override public void process(CommandLine cl) throws Exception { String config_file = null;/*from w w w. j a v a 2 s. c o m*/ List remaining_args = cl.getArgList(); if (remaining_args != null && !remaining_args.isEmpty()) { config_file = (String) remaining_args.get(0); } Map stormConf = Config.readStormConfig(null); String appId = cl.getOptionValue("appId"); if (appId == null) { throw new IllegalArgumentException("-appId is required"); } StormOnYarn storm = null; try { storm = StormOnYarn.attachToApp(appId, stormConf); StormMaster.Client client = storm.getClient(); switch (cmd) { case GET_STORM_CONFIG: downloadStormYaml(client, cl.getOptionValue("output")); break; case SET_STORM_CONFIG: String storm_conf_str = JSONValue.toJSONString(stormConf); try { client.setStormConf(storm_conf_str); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case ADD_SUPERVISORS: String supversiors = cl.getOptionValue("supervisors", "1"); try { client.addSupervisors(new Integer(supversiors).intValue()); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_NIMBUS: try { client.startNimbus(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_NIMBUS: try { client.stopNimbus(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_UI: try { client.startUI(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_UI: try { client.stopUI(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_SUPERVISORS: try { client.startSupervisors(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_SUPERVISORS: try { client.stopSupervisors(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case SHUTDOWN: try { client.shutdown(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; } } finally { if (storm != null) { storm.stop(); } } }
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 {/*from w w w . ja v a 2 s .c om*/ //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:assignment4.ProductServlet.java
/** * json format taken from/*from w w w . j a v a 2 s. c om*/ * https://code.google.com/p/json-simple/wiki/EncodingExamples * * @param query * @param params * @return */ private String getResults(String query, String... params) { StringBuilder sb = new StringBuilder(); String myString = ""; try (java.sql.Connection conn = credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } ResultSet rs = pstmt.executeQuery(); // sb.append("["); List list = new LinkedList(); while (rs.next()) { //sb.append(String.format("{ \"productId\" : %s , \"name\" : \"%s\", \"description\" : \"%s\", \"quantity\" : %s }" + ",\n", rs.getInt("productID"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"))); //sb.append(", "); Map map = new LinkedHashMap(); map.put("productID", rs.getInt("productID")); map.put("name", rs.getString("name")); map.put("description", rs.getString("description")); map.put("quantity", rs.getInt("quantity")); list.add(map); } myString = JSONValue.toJSONString(list); //sb.delete(sb.length() - 2, sb.length() - 1); //sb.append("]"); } catch (SQLException ex) { Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex); } return myString.replace("},", "},\n"); }
From source file:com.juniform.JUniformPackerJSON.java
@Override public String fromUniformObjectToString(JUniformObject object) { return JSONValue.toJSONString(this._toJSON(object)); }
From source file:amulet.appbuilder.AppBuilder.java
/** * Get the graphical structure of the current FSM. The structure is denoted as: * /* w w w. ja v a2 s . c o m*/ * { * "applications": [{ * "appname": "APP_NAME", * "states": [ * {"source": "SRC_STATE", "trigger": "TRIGGER_NAME", "target": "DEST_STATE"}, * ... * ]}, * ... * ] * } */ public String getFinalJSONGraphStructure() { return JSONValue.toJSONString(finalJSONGraphStructure); }