List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:ab.server.proxy.message.ProxyMouseWheelMessage.java
@SuppressWarnings("unchecked") @Override//w ww . j av a2 s. c om public JSONObject getJSON() { JSONObject o = new JSONObject(); o.put("delta", delta); return o; }
From source file:com.stratio.deep.commons.utils.CellsUtils.java
/** * converts from cell class to JSONObject * * @param cells the cells//from w ww . j a va 2 s . c o m * @return json from cell * @throws IllegalAccessException the illegal access exception * @throws IllegalAccessException the instantiation exception * @throws IllegalAccessException the invocation target exception */ public static JSONObject getJsonFromCell(Cells cells) throws IllegalAccessException, InstantiationException, InvocationTargetException { JSONObject json = new JSONObject(); for (Cell cell : cells) { if (cell.getCellValue() != null) { if (Collection.class.isAssignableFrom(cell.getCellValue().getClass())) { Collection c = (Collection) cell.getCellValue(); Iterator iterator = c.iterator(); List innerJsonList = new ArrayList<>(); while (iterator.hasNext()) { Object innerObject = iterator.next(); if (innerObject instanceof Cells) { innerJsonList.add(getJsonFromCell((Cells) innerObject)); } else { innerJsonList.add(innerObject); } } json.put(cell.getCellName(), innerJsonList); } else if (Cells.class.isAssignableFrom(cell.getCellValue().getClass())) { json.put(cell.getCellName(), getJsonFromCell((Cells) cell.getCellValue())); } else { json.put(cell.getCellName(), cell.getCellValue()); } } } return json; }
From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java
@SuppressWarnings("unchecked") private JSONObject newColumn(String label, String type) { JSONObject col = new JSONObject(); col.put("label", label); col.put("type", type); return col;/* w w w .j a v a 2s.c om*/ }
From source file:Json.JsonCodes.java
public void jsonCreate(String patchName) { JSONObject obj = new JSONObject(); JSONArray ar = new JSONArray(); for (int i = 0; i < this.pageList.size(); i++) { ar.add(this.pageList.get(i)); }//from w w w . j av a 2 s . co m obj.put("patch", this.patch); obj.put("page", ar); File file = new File(patchName); try { //?, ? ?? ? if (!file.exists()) { file.createNewFile(); } //PrintWriter ? ? ? PrintWriter out = new PrintWriter(file.getAbsoluteFile()); try { //? ? out.print(obj); } finally { //? // ?? out.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.imagelake.android.category.Servlet_categories.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); CategoriesDAOImp categoryDAOImp = new CategoriesDAOImp(); JSONArray ja = new JSONArray(); ArrayList<Categories> categoriesList = (ArrayList<Categories>) categoryDAOImp.listAllCategories(); if (!categoriesList.isEmpty()) { for (Categories cc : categoriesList) { JSONObject jo = new JSONObject(); jo.put("id", cc.getCategory_id()); jo.put("cat", cc.getCategory()); ja.add(jo);// ww w. j a v a 2 s. c o m } out.write("json=" + ja.toJSONString()); } else { JSONObject jo = new JSONObject(); jo.put("id", 0); jo.put("cat", "No category found."); ja.add(jo); out.write("json=" + ja.toJSONString()); } }
From source file:copter.WebSocketServerFactory.java
@Override public void onMessage(WebSocket conn, String message) { JSONObject res = new JSONObject(); String command = null;//from w ww . j a va 2 s .c o m JSONObject jsonObj = null; try { JSONParser parser = new JSONParser(); Object obj = parser.parse(message); jsonObj = (JSONObject) obj; command = (String) jsonObj.get("command"); if (command == null || command.isEmpty()) { return; } if (!command.equals(Constants.PING_COMMAND)) { logger.log("websocket message received: " + message); } switch (command) { case Constants.REBOOT_COMMAND: res.put("message", LinuxCommandsUtil.getInstance().rebootSystem()); break; case Constants.CAMERA_COMMAND: res.put("message", CameraControl.getInstance().doAction(jsonObj)); break; case Constants.GPS_COMMAND: res.put("message", GpsdConnector.getInstance().doAction(jsonObj, conn)); break; case Constants.HCSR04_COMMAND: res.put("message", HCSR04.getInstance().doAction(jsonObj, conn)); break; case Constants.MPU_COMMAND: res.put("message", MPU9150.getInstance().doAction(jsonObj, conn)); break; case Constants.ENGINE_COMMAND: Engine.getInstance().doAction(jsonObj, conn); break; case Constants.GPIO_COMMAND: res.put("message", GpioControl.getInstance().doAction(jsonObj)); break; case Constants.PING_COMMAND: res.put("status", "ok"); String ping_id = (String) jsonObj.get("ping_id"); res.put("ping_id", ping_id); break; default: res.put("message", "Unknown command '" + command + "'."); break; } } catch (Exception ex) { String err = "Json parse error: " + ex.getMessage(); logger.log(err); res.put("message", err); } if (!res.isEmpty()) { conn.send(res.toJSONString()); if (!command.equals(Constants.PING_COMMAND)) { logger.log("websocket response: " + res.toJSONString()); } } }
From source file:com.cloudera.lib.wsrs.TestJSONProvider.java
@Test @SuppressWarnings("unchecked") public void test() throws Exception { JSONProvider p = new JSONProvider(); Assert.assertTrue(p.isWriteable(JSONObject.class, null, null, null)); Assert.assertFalse(p.isWriteable(XTest.class, null, null, null)); Assert.assertEquals(p.getSize(null, null, null, null, null), -1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JSONObject json = new JSONObject(); json.put("a", "A"); p.writeTo(json, JSONObject.class, null, null, null, null, baos); baos.close();//from ww w . j a v a 2 s . co m Assert.assertEquals(new String(baos.toByteArray()).trim(), "{\"a\":\"A\"}"); }
From source file:me.prokopyl.storagemonitor.beans.JavaBean.java
@Override public String toJSONString() { JSONObject obj = new JSONObject(); obj.put("BeanType", this.getBeanName()); Field[] fields = this.getClass().getDeclaredFields(); for (Field field : fields) { if (Modifier.isTransient(field.getModifiers())) continue; field.setAccessible(true);/*w ww . jav a 2s. c o m*/ try { obj.put(field.getName(), field.get(this)); } catch (IllegalAccessException ex) { } } return obj.toJSONString(); }
From source file:Assignment4.Product.java
public String toJSON() { JSONObject obj = new JSONObject(); obj.put("productId", this.id); obj.put("productname", this.name); obj.put("description", this.description); obj.put("quantity", this.quantity); return obj.toJSONString(); }
From source file:com.punyal.medusaserver.californiumServer.core.MedusaValidation.java
public static Client check(String medusaServerAddress, String myTicket, String ticket) { CoapClient coapClient = new CoapClient(); Logger.getLogger("org.eclipse.californium.core.network.CoAPEndpoint").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.EndpointManager").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.stack.ReliabilityLayer").setLevel(Level.OFF); CoapResponse response;/*w ww . java 2 s . c o m*/ coapClient.setURI(medusaServerAddress + "/" + MEDUSA_SERVER_VALIDATION_SERVICE_NAME); JSONObject json = new JSONObject(); json.put(JSON_MY_TICKET, myTicket); json.put(JSON_TICKET, ticket); response = coapClient.put(json.toString(), 0); if (response != null) { //System.out.println(response.getResponseText()); try { json.clear(); json = (JSONObject) JSONValue.parse(response.getResponseText()); long expireTime = (Long) json.get(JSON_TIME_TO_EXPIRE) + (new Date()).getTime(); String userName = json.get(JSON_USER_NAME).toString(); String[] temp = json.get(JSON_ADDRESS).toString().split("/"); String address; if (temp[1] != null) address = temp[1]; else address = "0.0.0.0"; Client client = new Client(InetAddress.getByName(address), userName, null, UnitConversion.hexStringToByteArray(ticket), expireTime); return client; } catch (Exception e) { } } else { // TODO: take } return null; }