List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:net.metzweb.tinyserver.response.JsonResponse.java
/** * Convert Map to write JSON// w w w . j a v a 2 s .c o m * * @param code The request status code. * @param message The request message. * @param data The request data map (key => value). */ private void writeJson(STATUS_CODE code, String message, Object data) { Map json = new LinkedHashMap(); json.put("status", Integer.toString(code.getCode())); json.put("message", message); if (data != null) { json.put("data", data); } String jsonData = JSONValue.toJSONString(json); write(code.getHeader(), jsonData); }
From source file:backtype.storm.utils.ShellProcess.java
public void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
From source file:com.yahoo.storm.yarn.StormMasterServerHandler.java
@Override public String getStormConf() throws TException { LOG.info("getting configuration..."); return JSONValue.toJSONString(_storm_conf); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.ActionPointQuery.java
@SuppressWarnings("unchecked") public String execute(IServletConfig config, String[] parameters) { String vehicleId = parameters[3]; String apIndexString = parameters[4]; if (vehicleId == null || "".equals(vehicleId) || apIndexString == null || !apIndexString.matches("\\d+")) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " Invalid query!"); return JSONValue.toJSONString("Invalid query!"); }// w w w.j av a2 s . co m IVirtualVehicle vehicle = vehicleMap.get(vehicleId); if (vehicle == null) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " Vehicle not found (anymore)!"); return JSONValue.toJSONString("Vehicle not found (anymore)!"); } int actionPointIndex = Integer.valueOf(apIndexString); if (actionPointIndex > vehicle.getTaskList().size() - 1) { // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " No such action point!"); return JSONValue.toJSONString("No such action point!"); } JSONObject props = new JSONObject(); for (Entry<Object, Object> e : vehicle.getProperties().entrySet()) { props.put((String) e.getKey(), e.getValue()); } props.put(PROP_VEHICLE_LOCAL_NAME, vehicle.getWorkDir().getName()); if (vehicle.isProgramCorrupted()) { props.put(PROP_VEHICLE_STATE, "corrupt"); } else if (vehicle.isCompleted()) { props.put(PROP_VEHICLE_STATE, "completed"); } else if (vehicle.isActive()) { props.put(PROP_VEHICLE_STATE, "active"); } else { props.put(PROP_VEHICLE_STATE, "suspended"); } ITask cmd = vehicle.getTaskList().get(actionPointIndex); props.put(PROP_VEHICLE_ACTION_POINT, cmd.getPosition()); props.put(PROP_VEHICLE_TOLERANCE, cmd.getTolerance()); JSONArray act = new JSONArray(); for (IAction a : cmd.getActionList()) { act.add(a); } props.put(PROP_VEHICLE_ACTIONS, act); // LOG.info("action point " + parameters[0] + ":" + parameters[1] + ":" + parameters[2] + ":" + parameters[3] + ":" + parameters[4] + " " + JSONValue.toJSONString(props)); return JSONValue.toJSONString(props); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.TemperatureQuery.java
@SuppressWarnings("unchecked") public String execute(IServletConfig config, String[] parameters) { JSONArray obj = new JSONArray(); for (IVirtualVehicle vehicle : vehicleMap.values()) { if (vehicle.isFrozen()) { continue; }//from w w w. ja v a2 s.c om List<ITask> cmdList = vehicle.getTaskList(); for (ITask cmd : cmdList) { for (IAction action : cmd.getActionList()) { if (action instanceof Temperature && action.isComplete()) { Temperature actionTemp = (Temperature) action; JSONObject o = new JSONObject(); o.put("lat", Double.valueOf(cmd.getPosition().getLatitude())); o.put("lon", Double.valueOf(cmd.getPosition().getLongitude())); // o.put("alt", Double.valueOf(cmd.getPosition().getAltitude())); o.put("temp", Double.valueOf(actionTemp.getTemperature())); obj.add(o); } } } } return JSONValue.toJSONString(obj); }
From source file:com.conwet.silbops.model.basic.Attribute.java
@Override public String toJSONString() { return JSONValue.toJSONString(this.toJSON()); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.json.WaypointsQuery.java
public String execute(IServletConfig config, String[] parameters) { if (mapperProxy.getEngineInfoList() == null) { return ""; }/*from w ww . j a v a2s .c om*/ // TODO do this in parallel Map<String, Object> pilotWaypoints = new LinkedHashMap<String, Object>(); int pilotNumber = 0; for (EngineInfo engineInfo : mapperProxy.getEngineInfoList()) { String waypoints = null; String pilot = String.format(Locale.US, "pilot%03d", ++pilotNumber); try { String pilotName = engineInfo.getPilotName(); String waypointsUrl = engineInfo.getWaypointsUrl(); if (waypointsUrl != null) { waypoints = HttpQueryUtils.simpleQuery(waypointsUrl); Map<String, Object> p = new LinkedHashMap<String, Object>(); p.put("name", pilotName); p.put("waypoints", parser.parse(waypoints)); pilotWaypoints.put(pilot, p); } } catch (Exception e) { LOG.info("Can not query pilot " + pilot + ": " + waypoints, e); } } return JSONValue.toJSONString(pilotWaypoints); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.viewer.json.PositionQuery.java
public String execute(IServletConfig config, String[] parameters) throws IOException { if (mapperProxy.getEngineInfoList() == null) { return ""; }/* w w w . j a va 2 s. c om*/ // TODO do this in parallel Map<String, Object> pilotPositions = new LinkedHashMap<String, Object>(); int pilotNumber = 0; for (EngineInfo engineInfo : mapperProxy.getEngineInfoList()) { String position = null; String pilot = String.format(Locale.US, "pilot%03d", ++pilotNumber); try { String pilotName = engineInfo.getPilotName(); String pilotPosURL = engineInfo.getPositionUrl(); if (pilotPosURL != null) { position = HttpQueryUtils.simpleQuery(pilotPosURL); Map<String, Object> p = new LinkedHashMap<String, Object>(); p.put("name", pilotName); p.put("position", parser.parse(position)); pilotPositions.put(pilot, p); } } catch (Exception e) { LOG.info("Can not query pilot " + pilot + ": " + position, e); } } return JSONValue.toJSONString(pilotPositions); }
From source file:myproject.MyServer.java
public static void Update(HttpServletRequest request, HttpServletResponse response) throws IOException { try {// www.j av a2s . co m String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); Long student_id = (Long) json.get("student_id"); String student_name = (String) json.get("student_name"); Long regno = (Long) json.get("regno"); Double cgpa = (Double) json.get("cgpa"); String query = String.format( "UPDATE student " + "SET student_name='%s'," + "regno=%d," + "cgpa=%f " + "WHERE student_id=%d", JSONValue.escape(student_name), regno, cgpa, student_id); database.runUpdate(query); String result = database.getStudent(regno); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:net.cyberninjapiggy.apocalyptic.misc.UUIDFetcher.java
@SuppressWarnings("unchecked") private static String buildBody(List<String> names) { List<JSONObject> lookups = new ArrayList<>(); for (String name : names) { JSONObject obj = new JSONObject(); obj.put("name", name); obj.put("agent", AGENT); lookups.add(obj);/*w ww . ja v a 2 s . c om*/ } return JSONValue.toJSONString(lookups); }