List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:com.punyal.blackhole.utils.Parsers.java
public static JSONObject senml2json(String s) { JSONObject json, tmp;// w w w . jav a 2s .c o m String data; json = new JSONObject(); try { tmp = (JSONObject) JSONValue.parse(s); // Save base time json.put("time", tmp.get("bt")); JSONArray slideContent = (JSONArray) tmp.get("e"); Iterator i = slideContent.iterator(); while (i.hasNext()) { JSONObject slide = (JSONObject) i.next(); json.put(slide.get("n"), slide.get("v")); } } catch (NullPointerException e) { } return json; }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert from status of OFPhysicalPort to JSONArray * @param portList/*from w w w . j a v a2s.c om*/ * @return JSONArray of an ArrayList<OFPhysicalPort> */ public static JSONArray toPortStatus(List<OFPhysicalPort> portList) { JSONArray jsonArray = new JSONArray(); for (OFPhysicalPort pp : portList) { JSONObject obj = new JSONObject(); if (pp.getPortNumber() < 0) { continue; } obj.put("port_id", pp.getPortNumber()); obj.put("port_address", HexString.toHexString(pp.getHardwareAddress())); obj.put("config", pp.getConfig()); obj.put("supported", pp.getSupportedFeatures()); obj.put("current", pp.getCurrentFeatures()); obj.put("state", pp.getState()); FlowscaleController.logger.debug("port {}", pp.getPortNumber()); FlowscaleController.logger.debug("h/w {}", HexString.toHexString(pp.getHardwareAddress())); FlowscaleController.logger.debug("state {}", pp.getState()); FlowscaleController.logger.debug("-------"); jsonArray.add(obj); } return jsonArray; }
From source file:naftoreiclag.villagefive.util.json.AbstractJSONThingy.java
public String toJSONString() { JSONObject dummy = new JSONObject(); this.populateJson(dummy); return dummy.toJSONString(); }
From source file:net.jselby.pc.player.ChatMessage.java
/** * Converts a string to a basic ChatMessage * * @param message The String message//from ww w . j a va2 s . c om * @return A Chat message */ public static ChatMessage convertToJson(String message) { JSONObject obj = new JSONObject(); // Parse message, looking for colors etc. ArrayList<JSONObject> objects = new ArrayList<JSONObject>(); ChatColor color = ChatColor.WHITE; String currentMessage = ""; boolean nextByteAsColor = false; for (char bytes : message.toCharArray()) { if (nextByteAsColor) { color = ChatColor.getByChar(bytes); nextByteAsColor = false; continue; } if (bytes == ChatColor.COLOR_CHAR) { // Special color symbol if (currentMessage.length() > 0) { JSONObject currentMessageAsJSON = new JSONObject(); currentMessageAsJSON.put("text", currentMessage); currentMessageAsJSON.put("color", color.name().toLowerCase()); objects.add(currentMessageAsJSON); } color = ChatColor.WHITE; currentMessage = ""; nextByteAsColor = true; } else { currentMessage += bytes; } } if (currentMessage.length() > 0) { JSONObject rest = new JSONObject(); rest.put("text", currentMessage); rest.put("color", color.name().toLowerCase()); objects.add(rest); } JSONArray array = new JSONArray(); for (JSONObject jsonObject : objects) { array.add(jsonObject); } obj.put("extra", array); obj.put("text", ""); return new ChatMessage(obj); }
From source file:biz.vnc.zimbra.lighthistoryzimlet.MailhistoryReader.java
public String getRecord(String msgId) { JSONObject storejson = new JSONObject(); JSONArray jsonArray = new JSONArray(); try {/* ww w .ja v a 2 s . co m*/ dbConnection = LocalDB.connect(LocalConfig.get().db_name); String query = "SELECT * FROM mail_log_internal WHERE message_id=?" + "ORDER BY logtime ASC"; PreparedStatement statement = dbConnection.prepareStatement(query); statement.setString(1, msgId.trim()); ResultSet resultSet = statement.executeQuery(); ZLog.info("biz_vnc_lightweight_history", "Read Message Id" + msgId); while (resultSet.next()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("logtime", resultSet.getString("logtime")); if (resultSet.getString("from_localpart").equals("-") || resultSet.getString("from_domain").equals("-")) { jsonObject.put("from", "-"); } else { jsonObject.put("from", resultSet.getString("from_localpart") + "@" + resultSet.getString("from_domain")); } if (resultSet.getString("to_localpart").equals("-") || resultSet.getString("to_domain").equals("-")) { jsonObject.put("to", "-"); } else { jsonObject.put("to", resultSet.getString("to_localpart") + "@" + resultSet.getString("to_domain")); } jsonObject.put("moveto", resultSet.getString("foldername")); jsonObject.put("event", resultSet.getString("event")); jsonArray.add(jsonObject); } storejson.put("list", jsonArray); } catch (Exception e) { ZLog.err("mail-history", "getRecord: database query failed", e); } ZLog.info("biz_vnc_lightweight_history", "Recod Json :: " + storejson.toJSONString()); return storejson.toJSONString(); }
From source file:bizlogic.Sensors.java
public static void list(Connection DBcon) throws IOException, ParseException, SQLException { Statement st = null;/*ww w. j av a 2s . co m*/ ResultSet rs = null; try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT * FROM USERCONF.SENSORLIST"); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Sensors.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } try { FileWriter sensorsFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/sensors.json"); sensorsFile.write(""); sensorsFile.flush(); JSONParser parser = new JSONParser(); JSONObject Records = new JSONObject(); JSONObject operation_Obj = new JSONObject(); JSONObject operand_Obj = new JSONObject(); JSONObject unit_Obj = new JSONObject(); JSONObject name_Obj = new JSONObject(); JSONObject ip_Obj = new JSONObject(); JSONObject port_Obj = new JSONObject(); int _total = 0; JSONArray sensorList = new JSONArray(); while (rs.next()) { JSONObject sensor_Obj = new JSONObject(); int id = rs.getInt("sensor_id"); String operation = rs.getString("operation"); int operand = rs.getInt("operand"); String unit = rs.getString("unit"); String name = rs.getString("name"); String ip = rs.getString("IP"); int port = rs.getInt("port"); sensor_Obj.put("recid", id); sensor_Obj.put("operation", operation); sensor_Obj.put("operand", operand); sensor_Obj.put("unit", unit); sensor_Obj.put("name", name); sensor_Obj.put("IP", ip); sensor_Obj.put("port", port); sensorList.add(sensor_Obj); _total++; } rs.close(); Records.put("total", _total); Records.put("records", sensorList); sensorsFile.write(Records.toJSONString()); sensorsFile.flush(); sensorsFile.close(); } catch (IOException ex) { Logger.getLogger(Sensors.class.getName()).log(Level.WARNING, null, ex); } }
From source file:cs.rsa.ts14dist.common.CommandLanguage.java
@SuppressWarnings("unchecked") /** Create a valid reply object */ public static JSONObject createValidReplyWithReturnValue(Object returnValkue) { JSONObject reply = new JSONObject(); reply.put("error", false); reply.put("errorMsg", "OK"); reply.put(Constants.RETURNVALUE_KEY, returnValkue); return reply; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerTaller(HttpServletRequest request, HttpServletResponse response) throws IOException { TallerEntity e = CtrlUsuario.leerTaller(request.getParameter("1")); // id de la taller response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (e.getNombre().isEmpty()) { JSONObject obj = new JSONObject(); obj.put("isError", true); obj.put("errorDescrip", "El taller ya no esta disponible"); out.print(obj);//from www. j av a2s . c o m } else { JSONObject obj = new JSONObject(); obj.put("id", e.getIdTaller()); obj.put("nombre", e.getNombre()); obj.put("descripcion", e.getDescripcion()); obj.put("cupos", e.getCupos()); obj.put("costo", e.getCosto()); obj.put("fechaFin", "" + e.getFechaFinRegistro()); obj.put("fechaInicio", "" + e.getFechaInicio()); out.print(obj); } }
From source file:myproject.MyServer.java
public static void Query(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/* w w w . ja v a 2 s . c o m*/ String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); String query = (String) json.get("query"); String result = database.runQuery(query); 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:com.conwet.silbops.connectors.comet.JSONUtils.java
@SuppressWarnings("unchecked") public static JSONObject buildResponseMessage(String endpoinID, String string) { JSONObject json = new JSONObject(); json.put("endpointID", endpoinID); json.put("message", string); return json;/*from w w w . j a va 2 s . c o m*/ }