List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:com.oic.event.CmdEvent.java
@Override public void ActionEvent(JSONObject json, WebSocketListener webSocket) { String cmd = json.get("cmd").toString(); System.out.println("cmd : " + cmd); OicCharacter c = webSocket.getCharacter(); JSONObject json1 = new JSONObject(); switch (cmd) { case "userinfo": json1.put("id", c.getUserId()); json1.put("name", c.getName()); json1.put("studentId", c.getStudentNumber().toString()); json1.put("avaterId", c.getAvatarId()); json1.put("birthday", c.getBirthday().toString()); json1.put("mapid", c.getMapid()); break;/*from ww w. ja v a 2s .com*/ case "username": json1.put("name", webSocket.getCharacter().getName()); break; case "getchar": json1.put("method", "getchar"); json1.put("userid", 1); json1.put("username", "???"); json1.put("mapid", 31); Position pos = new Position(300, 200, 100, 230); json1.put("pos", Tools.convertPosToJSON(pos)); json1.put("avatar", 1); webSocket.sendJson(json1); json1.put("method", "getchar"); json1.put("userid", 2); json1.put("username", "??"); json1.put("mapid", 31); pos = new Position(150, 250, 100, 230); json1.put("pos", Tools.convertPosToJSON(pos)); json1.put("avatar", 2); webSocket.sendJson(json1); json1.put("method", "getchar"); json1.put("userid", 3); json1.put("username", "??"); json1.put("mapid", 31); pos = new Position(400, 200, 100, 230); json1.put("pos", Tools.convertPosToJSON(pos)); json1.put("avatar", 3); break; case "getmaplist": json1.put("method", "getmaplist"); new GetMapList().ActionEvent(json1, webSocket); break; case "getmapinfo": json1.put("method", "getmapinfo"); json1.put("mapid", json.get("mapid")); new GetMapInfo().ActionEvent(json1, webSocket); break; case "online": // JSONObject maps = new JSONObject(); MapFactory factory = MapFactory.getInstance(); for (OicMap map : factory.getMapList()) { String mapName = map.getMapName(); int count = map.getUserCont(); json1.put(mapName, count); } // json1.put("user", maps); break; } webSocket.sendJson(json1); }
From source file:de.root1.kad.smartvisu.AsyncReadRunnable.java
@Override public void run() { try {/*from w ww . java2 s .c om*/ String value = knx.read(address); if (value != null) { JSONObject jsonResponse = new JSONObject(); JSONObject jsonData = new JSONObject(); jsonData.put(address, value); jsonResponse.put(BackendServer.PARAM_DATA, jsonData); log.info("async response: {}", jsonResponse.toJSONString()); sse.sendMessage(null, null, jsonResponse.toJSONString()); } else { log.warn("Cannot read '" + address + "' async. Timeout?"); } } catch (KnxServiceException ex) { log.error("Error reading data from '" + address + "'", ex); } }
From source file:com.mobicage.rogerthat.form.LocationWidgetResult.java
@SuppressWarnings("unchecked") @Override//ww w .j a v a 2 s .c om public JSONObject toJSONObject() { JSONObject obj = new JSONObject(); obj.put("horizontal_accuracy", this.horizontalAccuracy); obj.put("vertical_accuracy", this.verticalAccuracy); obj.put("latitude", this.latitude); obj.put("longitude", this.longitude); obj.put("altitude", this.altitude); obj.put("timestamp", this.timestamp); return obj; }
From source file:com.oic.event.SetProfile.java
@Override public void ActionEvent(JSONObject json, WebSocketListener webSocket) { JSONObject responseJSON = new JSONObject(); responseJSON.put("method", "setprofile"); if (!validation(json, webSocket)) { return;/*w w w . j av a 2s .com*/ } Connection con = DatabaseConnection.getConnection(); PreparedStatement ps; try { con = DatabaseConnection.getConnection(); con.setAutoCommit(false); String sql = "UPDATE user SET studentnumber = ?, name = ?, avatarid = ?, grade = ?, sex = ?, birth = ?, comment = ? " + "WHERE userid = ?"; ps = con.prepareStatement(sql); ps.setString(1, json.get("studentid").toString()); ps.setString(2, json.get("username").toString()); ps.setInt(3, Integer.parseInt(json.get("avatarid").toString())); ps.setInt(4, Integer.parseInt(json.get("grade").toString())); ps.setInt(5, Integer.parseInt(json.get("gender").toString())); ps.setDate(6, toDate(json.get("birthday").toString())); ps.setString(7, json.get("comment").toString()); ps.setLong(8, webSocket.getCharacter().getUserId()); ps.executeUpdate(); ps.close(); sql = "UPDATE setting SET privategrade = ?, privatesex = ?, privatebirth =? WHERE userid = ?"; ps = con.prepareStatement(sql); ps.setInt(1, Integer.parseInt(json.get("vgrade").toString())); ps.setInt(2, Integer.parseInt(json.get("vgender").toString())); ps.setInt(3, Integer.parseInt(json.get("vbirthday").toString())); ps.setLong(4, webSocket.getCharacter().getUserId()); ps.executeUpdate(); ps.close(); con.commit(); //TODO responseJSON.put("status", 0); } catch (Exception e) { try { con.rollback(); } catch (SQLException sq) { LOG.warning("[setProfile]Error Rolling back."); } e.printStackTrace(); responseJSON.put("status", 1); } finally { try { con.setAutoCommit(true); } catch (SQLException ex) { Logger.getLogger(SetProfile.class.getName()).log(Level.WARNING, "Error going back to AutoCommit mode", ex); } } webSocket.sendJson(responseJSON); }
From source file:com.intouch.action.EventProcessor.java
@Override public JSONObject processRequest(Map<String, String[]> params) throws ServerQueryException { DataHelper dataHelper = DataHelper.getInstance(); User user = dataHelper.getUserByToken(params.get("token")[0]); JSONObject response;//from w ww . j a v a2 s.c om response = new JSONObject(); try { isParameterExist(params, "name"); isParameterExist(params, "description"); isParameterExist(params, "gps"); isParameterExist(params, "id"); isParameterExist(params, "date_time"); isParameterExist(params, "address"); isParameterExist(params, "token"); isApiKeyValid(params.get("api_key")[0]); } catch (ServerQueryException ex) { response.put("result", "error"); response.put("error_type", ex.getMessage()); return response; } Event event = null; Date date_time = null; try { date_time = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(params.get("date_time")[0]); } catch (ParseException ex) { Logger.getLogger(EventProcessor.class.getName()).log(Level.SEVERE, null, ex); date_time = new Date(); } event = new Event(user, params.get("name")[0], params.get("gps")[0], date_time, params.get("address")[0], new Date()); event.setDescription(params.get("description")[0]); dataHelper.createNewEvent(event); Gson gson = new Gson(); response.put("result", "success"); response.put("event", gson.toJson(event, Event.class)); return response; }
From source file:net.jselby.pc.network.JoinHandler.java
public static void join(ChannelHandlerContext ctx, Client cl) { ConnectedClient client = (ConnectedClient) cl; System.out.println(cl.name + "[" + ctx.channel().remoteAddress() + "] logged in with entity id " + cl.id + " at ([world] " + cl.x + ", " + cl.y + ", " + cl.z + ")"); // Welcome messages PacketOutChatMessage joinMsg = new PacketOutChatMessage(); joinMsg.message = ChatMessage.convertToJson("Welcome to the server!"); joinMsg.message.json.put("color", "gold"); cl.writePacket(joinMsg);/*from w w w . j a v a 2 s . c o m*/ joinMsg.message = ChatMessage.convertToJson("This server is running PoweredCube - http://pc.jselby.net"); joinMsg.message.json.put("color", "gold"); JSONObject clickEvent = new JSONObject(); clickEvent.put("action", "open_url"); clickEvent.put("value", "http://pc.jselby.net"); joinMsg.message.json.put("clickEvent", clickEvent); cl.writePacket(joinMsg); joinMsg.message = ChatMessage.convertToJson("Any number of bugs can occur. You have been warned!"); joinMsg.message.json.put("color", "red"); cl.writePacket(joinMsg); // Spawn entity for (Client c : PoweredCube.getInstance().clients .toArray(new Client[PoweredCube.getInstance().clients.size()])) { PlayerDisplayer.showPlayer(client, c); } BukkitPlayer p = new BukkitPlayer(cl); PoweredCube.getInstance().players.add(p); PoweredCube.getInstance().clients.add(cl); joinMsg.message = ChatMessage.convertToJson(cl.displayName + " joined the server."); PoweredCube.getInstance().distributePacket(joinMsg); }
From source file:ab.server.proxy.message.ProxyClickMessage.java
@SuppressWarnings("unchecked") @Override//from w w w . ja v a2 s . c o m public JSONObject getJSON() { JSONObject o = new JSONObject(); o.put("x", x); o.put("y", y); return o; }
From source file:mikolaj.torrent.communication.server.actions.Shares.java
public Result perform(HashMap<String, String> paramsMap) { File[] files = new File(Service.getInstance().getServer().getShareDirectory()).listFiles(); List<JSONObject> fileCollection = new ArrayList<>(); try {/*from www . j a v a 2 s . com*/ for (File file : files) { if (!file.isDirectory()) { JSONObject fileObject = new JSONObject(); fileObject.put("fileName", file.getName().replace(" ", "__")); fileObject.put("checkSum", Checksum.getMD5Checksum(file.getAbsolutePath())); fileCollection.add(fileObject); } } } catch (Exception ex) { System.out .println("Problem with share you files list, check your permission to application. Exiting..."); System.exit(1); } Result result = new Result(); result.saveJson(fileCollection); return result; }
From source file:modelo.UsuariosManagers.Roles.java
public JSONArray getRoles(String usuario, String rol, String codigo) throws SQLException { SeleccionarRoles select = new SeleccionarRoles(); ResultSet rset = select.getRoles(codigo, usuario); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getString("PK_CODIGO")); jsonObject.put("descripcion", rset.getString("VAR_ROL")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/*from ww w. j a v a 2 s . c o m*/ select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }
From source file:mml.handler.scratch.ScratchLayer.java
public JSONObject toJSONObject() { JSONObject jObj = new JSONObject(); jObj.put(JSONKeys.NAME, name); jObj.put(JSONKeys.BODY, mml); return jObj; }