List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.piusvelte.hydra.ConnectionManager.java
@SuppressWarnings("unchecked") JSONObject getDatabase(String database) { JSONObject response = new JSONObject(); JSONArray rows = new JSONArray(); synchronized (databaseLock) { if (sDatabaseSettings.containsKey(database)) { JSONArray rowData = new JSONArray(); HashMap<String, String> databaseSettings = sDatabaseSettings.get(database); rowData.add(database); rowData.add(databaseSettings.get(sDatabase)); rowData.add(databaseSettings.get(sHost)); rowData.add(databaseSettings.get(sPort)); rowData.add(databaseSettings.get(sType)); rows.add(rowData);//from www . ja va 2 s . c om } } response.put("result", rows); return response; }
From source file:net.duckling.ddl.web.controller.pan.LynxPanController.java
@WebLog(method = "PandeleteResources", params = "rids[]") @RequestMapping(params = "func=deleteResources") public void deleteResources(HttpServletRequest request, HttpServletResponse response) { String[] ridStrs = request.getParameterValues("rids[]"); List<String> rids = new ArrayList<String>(); for (String r : ridStrs) { rids.add(decode(r));//from w w w .j a v a 2 s . co m } List<String> errorList = new ArrayList<String>(); List<String> successList = new ArrayList<>(); PanAcl acl = PanAclUtil.getInstance(request); for (String r : rids) { try { boolean result = service.rm(acl, r); if (!result) { errorList.add(encode(r)); } else { successList.add(encode(r)); } } catch (MeePoException e) { LOG.error("", e); errorList.add(encode(r)); } } JSONObject o = new JSONObject(); o.put("result", errorList.isEmpty()); if (!errorList.isEmpty()) { JSONArray array = new JSONArray(); for (String s : errorList) { array.add(s); } o.put("errorRids", array); JSONArray suc = new JSONArray(); for (String s : successList) { suc.add(s); } o.put("sucRids", suc); } LOG.info(acl.getUid() + " delete " + successList + " ;delete error" + errorList); JsonUtil.writeJSONObject(response, o); }
From source file:gwap.rest.LocationService.java
/** * A topic denotes the set of pictues that can be used in a game such as "Munich" or "Baroque" * /*from w w w . j av a 2s .c o m*/ * @param userId * @return */ @GET @Path("/topics") // $HOST/seam/resource/rest/location/topics @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("unchecked") public Response getTopics(@QueryParam("userid") String userId) { if (userId == null) return Response.status(Response.Status.NOT_ACCEPTABLE).build(); Query query = entityManager.createNamedQuery("virtualTaggingType.all"); ArrayList<VirtualTaggingType> virtualTaggingTypes = (ArrayList<VirtualTaggingType>) query.getResultList(); JSONArray jsonArray = new JSONArray(); for (VirtualTaggingType virtualTaggingType : virtualTaggingTypes) { JSONObject jsonObject = new JSONObject(); jsonObject.put("text", virtualTaggingType.getName()); jsonObject.put("value", virtualTaggingType.getId()); jsonObject.put("available", true); //TODO: Calculate availability jsonArray.add(jsonObject); } log.info("UserId: #0", userId); return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON).build(); }
From source file:com.orthancserver.SelectImageDialog.java
public String Serialize() { JSONArray servers = new JSONArray(); for (int i = 0; i < root_.getChildCount(); i++) { MyTreeNode node = (MyTreeNode) root_.getChildAt(i); servers.add(node.GetConnection().Serialize()); }/*from ww w.j a va2 s . co m*/ String config = servers.toJSONString(); return DatatypeConverter.printBase64Binary(config.getBytes()); }
From source file:net.matthewauld.racetrack.server.WrSQL.java
@SuppressWarnings("unchecked") public String getJSONClassSpecificRiders(String query, String classID) throws SQLException { connect();//from w w w. j a v a 2 s . c om st = con.createStatement(); rs = st.executeQuery(query); JSONObject json = new JSONObject(); JSONArray riders = new JSONArray(); while (rs.next()) { JSONObject classJSON = new JSONObject(); classJSON.put("name", fetchRiderName(rs.getInt("id"))); classJSON.put("id", rs.getInt("id")); riders.add(classJSON); } JSONObject classInfo = new JSONObject(); classInfo.put("title", fetchClassTitle(Integer.parseInt(classID))); classInfo.put("cid", Integer.parseInt(classID)); json.put("class", classInfo); if (riders.size() == 0) { json.put("riders", null); } else { json.put("riders", riders); } return json.toJSONString(); }
From source file:com.splunk.logging.HttpEventCollectorSender.java
@SuppressWarnings("unchecked") // JSONObject does not understand that Map should be parameterised. private JSONObject writeThrowableInfoToJson(HttpEventCollectorThrowableInfo throwableInfo) { if (throwableInfo == null) { return null; }/*w w w . j av a 2s . c om*/ final JSONObject json = new JSONObject(); putIfPresent(json, "throwable_message", throwableInfo.getMessage()); putIfPresent(json, "throwable_class", throwableInfo.getClassName()); final JSONArray stackTrace = new JSONArray(); json.put("stack_trace", stackTrace); if (throwableInfo.getStackTraceElements() != null) { for (final String strackTraceElement : throwableInfo.getStackTraceElements()) { stackTrace.add(strackTraceElement); } } final JSONObject cause = writeThrowableInfoToJson(throwableInfo.getCause()); if (cause != null) { json.put("cause", cause); } return json; }
From source file:cc.pinel.mangue.storage.MangaStorage.java
public void addManga(Manga manga) throws IOException { JSONObject json = null;/*from w ww . ja v a2s.co m*/ try { json = readJSON(); } catch (Exception e) { // ignored } if (json == null) json = new JSONObject(); JSONArray jsonMangas = (JSONArray) json.get("mangas"); if (jsonMangas == null) { jsonMangas = new JSONArray(); json.put("mangas", jsonMangas); } JSONObject jsonManga = findManga(jsonMangas, manga.getId()); if (jsonManga == null) { jsonManga = new JSONObject(); jsonManga.put("id", manga.getId()); jsonManga.put("name", manga.getName()); jsonManga.put("path", manga.getPath()); jsonMangas.add(jsonManga); Object[] sortedArray = jsonMangas.toArray(); Arrays.sort(sortedArray, new Comparator() { public int compare(Object o1, Object o2) { JSONObject manga1 = (JSONObject) o1; JSONObject manga2 = (JSONObject) o2; return manga1.get("name").toString().compareTo(manga2.get("name").toString()); } }); JSONArray sortedJSONArray = new JSONArray(); for (int i = 0; i < sortedArray.length; i++) sortedJSONArray.add(sortedArray[i]); json.put("mangas", sortedJSONArray); writeJSON(json); } }
From source file:bhl.pages.handler.PagesListHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MissingDocumentException { try {//w ww . j a v a 2s. c o m String docid = request.getParameter(Params.DOCID); if (docid != null) { Connection conn = Connector.getConnection(); String[] keys = new String[2]; keys[0] = JSONKeys.BHL_PAGE_ID; keys[1] = JSONKeys.PAGE_SEQUENCE; String[] pages = conn.listCollectionBySubKey(Database.PAGES, JSONKeys.IA_IDENTIFIER, docid, keys); JSONArray list = new JSONArray(); for (int i = 0; i < pages.length; i++) { JSONObject jobj = (JSONObject) JSONValue.parse(pages[i]); Number pageNo = (Number) jobj.get(JSONKeys.PAGE_SEQUENCE); Number pageId = (Number) jobj.get(JSONKeys.BHL_PAGE_ID); System.out.println("pageNo=" + pageNo + " pageId=" + pageId); PageDesc ps = new PageDesc(new Integer(pageNo.intValue()).toString(), new Integer(pageId.intValue()).toString()); list.add(ps.toJSONObject()); } PagesGetHandler.sortList(list); response.setContentType("application/json"); response.getWriter().print(list.toJSONString()); } else throw new Exception("Must specify document identifier"); } catch (Exception e) { throw new MissingDocumentException(e); } }
From source file:azkaban.web.pages.FlowExecutionServlet.java
@SuppressWarnings("unchecked") private String createJsonFlow(Flow flow) { JSONObject jsonFlow = new JSONObject(); jsonFlow.put("flow_id", flow.getId()); if (!flow.isLayedOut()) { DagLayout layout = new SugiyamaLayout(flow); layout.setLayout();/*from ww w. ja v a 2 s .c o m*/ } JSONArray jsonNodes = new JSONArray(); for (FlowNode node : flow.getFlowNodes()) { JSONObject jsonNode = new JSONObject(); jsonNode.put("name", node.getAlias()); jsonNode.put("x", node.getX()); jsonNode.put("y", node.getY()); jsonNode.put("status", node.getStatus()); jsonNodes.add(jsonNode); } JSONArray jsonDependency = new JSONArray(); for (Dependency dep : flow.getDependencies()) { JSONObject jsonDep = new JSONObject(); jsonDep.put("dependency", dep.getDependency().getAlias()); jsonDep.put("dependent", dep.getDependent().getAlias()); jsonDependency.add(jsonDep); } jsonFlow.put("nodes", jsonNodes); jsonFlow.put("timestamp", flow.getLastModifiedTime()); jsonFlow.put("layouttimestamp", flow.getLastLayoutModifiedTime()); jsonFlow.put("dependencies", jsonDependency); return jsonFlow.toJSONString(); }
From source file:com.appcelerator.titanium.desktop.ui.wizard.TiManifest.java
/** * Writes the timanifest file based ont he passed in arguments and the existing metadata for the project. Does no * validation!/*from ww w. j ava 2s . co m*/ * * @param networkRuntime * "network" || "include" * @param release * Release to users? * @param visibility * "public" || "private" * @param showSplash * - Should the install splash screen be shown on first run of app? true || false */ @SuppressWarnings("unchecked") IStatus write(Set<String> platforms, String networkRuntime, boolean release, String visibility, boolean showSplash, IProgressMonitor monitor) { SubMonitor sub = SubMonitor.convert(monitor, 5); JSONObject timanifest = new JSONObject(); TitaniumProject tiProj = getTitaniumProject(); timanifest.put(APPNAME, tiProj.getAppName()); timanifest.put(APPID, tiProj.getAppID()); timanifest.put(APPVERSION, tiProj.getVersion()); timanifest.put(MID, getMID()); timanifest.put(PUBLISHER, tiProj.getPublisher()); timanifest.put(URL, tiProj.getURL()); timanifest.put(DESC, tiProj.getDescription()); timanifest.put(RELEASE, release); timanifest.put(NO_INSTALL, !showSplash); timanifest.put(GUID, getGUID()); timanifest.put(VISIBILITY, visibility); JSONObject runtime = new JSONObject(); try { runtime.put("version", getProjectSDKVersion()); //$NON-NLS-1$ } catch (CoreException e) { return e.getStatus(); } runtime.put(PACKAGE, networkRuntime); timanifest.put(RUNTIME, runtime); if (tiProj.getImage() != null) { // FIXME What should we do here? // var image = TFS.getFile(project.image); // timanifest.image = image.name(); timanifest.put("image", tiProj.getImage()); //$NON-NLS-1$ } sub.worked(1); // OS options JSONArray array = new JSONArray(); array.addAll(platforms); timanifest.put(PLATFORMS, array); if (TitaniumConstants.DESKTOP_TYPE.equals(tiProj.getType())) { JSONArray modules = new JSONArray(); Map<MODULE, String> moduleMap = tiProj.getModules(); for (Map.Entry<MODULE, String> entry : moduleMap.entrySet()) { JSONObject m = new JSONObject(); m.put("name", entry.getKey().getKey()); //$NON-NLS-1$ m.put("version", entry.getValue()); //$NON-NLS-1$ m.put(PACKAGE, networkRuntime); modules.add(m); } timanifest.put("modules", modules); //$NON-NLS-1$ } else { timanifest.put("package_target", "test"); //$NON-NLS-1$ //$NON-NLS-2$ } sub.worked(1); IFile file = project.getFile(FILENAME); try { if (!file.exists()) { file.create(new ByteArrayInputStream(timanifest.toJSONString().getBytes()), IResource.FORCE, sub.newChild(1)); } else { file.setContents(new ByteArrayInputStream(timanifest.toJSONString().getBytes()), IResource.FORCE, sub.newChild(1)); } } catch (CoreException e) { return e.getStatus(); } sub.done(); return Status.OK_STATUS; }