List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.mobicage.rogerthat.SearchConfig.java
@SuppressWarnings("unchecked") @Override/*from w ww.j a v a 2s. c o m*/ public JSONObject toJSONObject() { JSONObject jsonObject = new JSONObject(); jsonObject.put("enabled", enabled); jsonObject.put("keywords", keywords); JSONArray jsonArray = new JSONArray(); for (SearchLocation l : locations) { jsonArray.add(l.toJSONObject()); } jsonObject.put("locations", jsonArray); return jsonObject; }
From source file:org.kitodo.data.elasticsearch.index.type.BaseType.java
/** * Method for adding relationship between bean objects. * /*from w w w . java 2 s. c o m*/ * @param objects * list * @return JSONArray */ @SuppressWarnings("unchecked") <F extends BaseBean> JSONArray addObjectRelation(List<F> objects) { JSONArray jsonArray = new JSONArray(); if (objects != null) { for (F property : objects) { jsonArray.add(addIdForRelation(property.getId())); } } return jsonArray; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.VehicleDetailsQuery.java
@SuppressWarnings("unchecked") @Override//from ww w .ja va 2 s . com public String execute(IServletConfig config, String[] parameters) throws IOException { String vehicleId = parameters[3]; if (vehicleId == null || "".equals(vehicleId)) { return JSONValue.toJSONString("Invalid query!"); } IVirtualVehicle vehicle = vehicleMap.get(vehicleId); if (vehicle == null) { return JSONValue.toJSONString("Vehicle not found (anymore)!"); } 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"); } JSONArray tasks = new JSONArray(); for (ITask cmd : vehicle.getTaskList()) { tasks.add(cmd); } props.put(PROP_VEHICLE_TASKS, tasks); return JSONValue.toJSONString(props); }
From source file:compare.handler.get.TableInfoHandler.java
/** * Handle a request to get some metadata for a document * @param request the http request/* w w w .j a va 2 s . c o m*/ * @param response the response * @param urn the current urn (ignored) * @throws CompareException if loading of MVD failed */ public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws CompareException { Map map = request.getParameterMap(); docid = request.getParameter(JSONKeys.DOCID); version1 = getStringOption(map, Params.VERSION1, ""); String json = "{}"; try { if (docid != null && docid.length() > 0) { EcdosisMVD mvd = loadMVD(Database.CORTEX, docid); String selected = getStringOption(map, Params.SELECTED, ALL); String baseVersion = selectVersion1(mvd, selected); short base = mvd.getBaseVersion(baseVersion); int baseLen = getBaseVersionLen(mvd, base); int[] offsets = mvd.measureTable(base); int numSegs = Math.round((float) offsets.length / (float) CHUNK); if (numSegs == 0) numSegs = 1; int[] segs = new int[numSegs + 1]; if (numSegs == 2) { segs[0] = 0; segs[1] = baseLen; } else { for (int i = 0; i < numSegs; i++) segs[i] = offsets[i * CHUNK]; } segs[segs.length - 1] = baseLen; JSONArray arr = new JSONArray(); for (int i = 0; i < segs.length; i++) arr.add(segs[i]); json = arr.toJSONString(); } else throw new Exception("CORTEX mvd " + docid + " not found"); response.setContentType("application/json;charset=UTF-8"); response.getWriter().println(json); } catch (Exception e) { throw new CompareException(e); } }
From source file:controller.RetrieveSchema.java
@SuppressWarnings("unchecked") public String retrieveSchema(String _projectId) throws IOException, DatabaseException, MissingPropertiesFile, SQLException, ConnectionClosedException, DatabaseValueNotFoundException { JSONObject obj = new JSONObject(); dao = new GetSchemaDao(); Schema schema = dao.getSchema(Integer.parseInt(_projectId)); JSONArray tables = new JSONArray(); JSONArray columns = new JSONArray(); for (Table table : schema.getTables()) { tables.add(table.getName()); }// w ww .java 2 s .c o m for (Column column : schema.getColumns()) { columns.add(column.getName()); } obj.put("tables", tables); obj.put("columns", columns); return json.nestedJson(State.PASSED, obj); }
From source file:com.xtructure.xevolution.tool.data.AbstractDataXIdObject.java
@Override @SuppressWarnings("unchecked") public final JSONAware toJSON() { JSONArray jsonArray = new JSONArray(); jsonArray.add(getId().toString()); jsonArray.add(jsonObject);//w ww .j a va2 s .com return jsonArray; }
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)); }// ww w . java 2s.com 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.au.splashinc.JControl.Load.DarkForcesJsonLoader.java
public void LoadConfig() { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //JSON organised in [Button/Axis/POV],{[TypeofAction],[Value]} /*W- up - LeftStick Up A - Left - Right Stick Left - X Rot - S - back - LeftStick Down - Y Axis up d - right - Right Stick Right - x Rot + Space - jump - A - 1/*from w w w. j a va 2 s. c o m*/ c - Crouch - Right Stick In - 10 Mouse 1 - primary fire - Right Trigger - z axis - Shift - Run - Left Stick in - 9 Capslock - Walk - LB - 5 e - Open/interact - B - 2 R - Secondary Fire - Left Trigger - z axis + Pageup - Look Up - Right Stick Up - Y Rot - PageDown - Loop Down - Right Stick Down - y Rot + f1 - pda - Back - 3 f2 - night vision - dpad down f3- fleats - dpad left f4 - gasmask - dpad right f5 - headlamp - dpad up*/ JSONArray simpleKey = new JSONArray(); simpleKey.add(GetJSONObject("Button 0", KeyEvent.VK_SPACE)); simpleKey.add(GetJSONObject("Button 2", KeyEvent.VK_E)); simpleKey.add(GetJSONObject("Button 8", KeyEvent.VK_F1)); simpleKey.add(GetJSONObject("Button 7", KeyEvent.VK_CAPS_LOCK)); simpleKey.add(GetJSONObject("Button 3", KeyEvent.VK_SHIFT)); simpleKey.add(GetJSONObject("Button 1", KeyEvent.VK_C)); simpleKey.add(GetJSONObject("X Axis -", KeyEvent.VK_A)); simpleKey.add(GetJSONObject("X Axis +", KeyEvent.VK_D)); simpleKey.add(GetJSONObject("Y Axis -", KeyEvent.VK_W)); simpleKey.add(GetJSONObject("Y Axis +", KeyEvent.VK_S)); simpleKey.add(GetJSONObject("Hat Switch 0 0.25", KeyEvent.VK_F5)); simpleKey.add(GetJSONObject("Hat Switch 0 0.5", KeyEvent.VK_F4)); simpleKey.add(GetJSONObject("Hat Switch 0 0.75", KeyEvent.VK_F2)); simpleKey.add(GetJSONObject("Hat Switch 0 1.0", KeyEvent.VK_F3)); simpleKey.add(GetJSONObject("Z Axis +", KeyEvent.VK_R)); simpleKey.add(GetJSONObject("Y Rotation +", KeyEvent.VK_PAGE_UP)); simpleKey.add(GetJSONObject("Y Rotation -", KeyEvent.VK_PAGE_DOWN)); JSONArray simpleMouse = new JSONArray(); simpleMouse.add(GetJSONObject("X Rotation", "LeftRight")); simpleMouse.add(GetJSONObject("Z Axis -", InputEvent.BUTTON1_MASK)); //JSONObject jo = new JSONObject(); //jo.put("Button 0", KeyEvent.VK_SPACE); //jo.put("Button 2", KeyEvent.VK_E); //jo.pu //simpleKey.add(jo); /*JSONObject j1 = new JSONObject(); j1.put("Button 2", KeyEvent.VK_E); simpleKey.add(j1);*/ json.put(ControllerAction.SIMPLE_BUTTON.toString(), simpleKey); json.put(ControllerAction.SIMPLE_MOUSE.toString(), simpleMouse); /*json.put("Button 0", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_SPACE)); json.put("Button 2", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_E)); json.put("Button 8", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_F1)); json.put("Button 7", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_CAPS_LOCK)); json.put("Button 3", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_SHIFT)); json.put("Button 1", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_C)); json.put("X Axis -", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_A)); json.put("X Axis +", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_D)); json.put("Y Axis -", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_W)); json.put("Y Axis +", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_S)); json.put("Hat Switch 0 0.25", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_F5)); json.put("Hat Switch 0 0.5", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_F4)); json.put("Hat Switch 0 0.75", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_F2)); json.put("Hat Switch 0 1.0", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_F3)); json.put("Z Axis +", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_R)); json.put("Z Axis -", GetSimpleButton(ControllerAction.SIMPLE_MOUSE.toString(), InputEvent.BUTTON1_MASK)); json.put("X Rotation", GetSimpleButton(ControllerAction.SIMPLE_MOUSE.toString(), "LeftRight")); json.put("Y Rotation +", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_PAGE_UP)); json.put("Y Rotation -", GetSimpleButton(ControllerAction.SIMPLE_BUTTON.toString(), KeyEvent.VK_PAGE_DOWN));*/ //json.put("Button 4,5", this) controllerDetail = json.toJSONString(); System.out.println(json.toJSONString()); JsonLoaderHelper jsh = new JsonLoaderHelper(json); keyDownMap = jsh.getKeyDownMap(); keyUpMap = jsh.getKeyUpMap(); mouseMoveMap = jsh.getMouseMoveMap(); mouseButtonDownMap = jsh.getMouseButtonDownMap(); mouseButtonUpMap = jsh.getMouseButtonUpMap(); }
From source file:com.telefonica.iot.cygnus.utils.NGSIUtilsTest.java
/** * [NGSIUtils.getGeometry] -------- When getting a geometry, a CartoDB point is obtained when passing * an attribute with 'geometry' metadata. *//*from ww w .j a v a2s . c o m*/ @Test public void testGetGeometryMetadata() { System.out.println(getTestTraceHead("[Utils.getLocation]") + "-------- When getting a geometry, a CartoDB point is obtained when passing an attribute " + "with 'location' metadata"); JSONObject metadataJson = new JSONObject(); metadataJson.put("name", "location"); metadataJson.put("type", "string"); metadataJson.put("value", "WGS84"); JSONArray metadatasJson = new JSONArray(); metadatasJson.add(metadataJson); String attrMetadataStr = metadatasJson.toJSONString(); String attrValue = "-3.7167, 40.3833"; String attrType = "coordinates"; // irrelevant for this test boolean swapCoordinates = false; // irrelevant for this test ImmutablePair<String, Boolean> geometry = NGSIUtils.getGeometry(attrValue, attrType, attrMetadataStr, swapCoordinates); try { assertEquals("ST_SetSRID(ST_MakePoint(-3.7167,40.3833), 4326)", geometry.getLeft()); System.out.println(getTestTraceHead("[Utils.getLocation]") + "- OK - Geometry '" + geometry.getLeft() + "' obtained for an attribute with metadata '" + attrMetadataStr + "' and value '" + attrValue + "'"); } catch (AssertionError e) { System.out.println(getTestTraceHead("[Utils.getLocation]") + "- FAIL - Geometry '" + geometry.getLeft() + "' obtained for an attribute with metadata '" + attrMetadataStr + "' and value '" + attrValue + "'"); throw e; } // try catch // try catch }
From source file:de.hstsoft.sdeep.NoteManager.java
@SuppressWarnings("unchecked") private void saveNotes() { JSONObject envelope = new JSONObject(); envelope.put("version", VERSION); JSONArray jsonArray = new JSONArray(); for (Note n : notes) { jsonArray.add(n.toJson()); }// www . j ava2 s . c o m envelope.put("notes", jsonArray); try { File file = new File(directory + FILENAME); FileWriter fileWriter = new FileWriter(file); fileWriter.append(envelope.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }