List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:azkaban.web.pages.IndexServlet.java
@SuppressWarnings("unchecked") private String getJSONJobsForFolder(FlowManager manager, String folder) { List<String> rootJobs = manager.getRootNamesByFolder(folder); Collections.sort(rootJobs);/*from ww w . j a v a 2 s . c o m*/ JSONArray rootJobObj = new JSONArray(); for (String root : rootJobs) { Flow flow = manager.getFlow(root); JSONObject flowObj = getJSONDependencyTree(flow); rootJobObj.add(flowObj); } return rootJobObj.toJSONString(); }
From source file:net.duckling.ddl.web.AbstractRecommendContrller.java
@SuppressWarnings("unchecked") protected void prepareRecommend(HttpServletResponse response) { Team team = teamService.getTeamByID(VWBContext.getCurrentTid()); List<SimpleUser> candidates = teamMemberService.getTeamMembersOrderByName(team.getId()); Collections.sort(candidates, comparator); JSONArray array = new JSONArray(); for (SimpleUser current : candidates) { JSONObject temp = new JSONObject(); temp.put("id", current.getUid()); if (StringUtils.isNotEmpty(current.getName())) { temp.put("name", current.getName()); } else {/* w w w.j a v a 2 s.c o m*/ temp.put("name", current.getUid()); } temp.put("userExtId", current.getId()); array.add(temp); } JsonUtil.writeJSONObject(response, array); }
From source file:com.amindorost.searchalgorithms.MainSearch.java
protected Node updateNodesQueue() { JSONObject currentIteration = new JSONObject(); JSONArray queueJSONArray = new JSONArray(); JSONObject queueJSON;/*w ww. j a v a2 s. com*/ for (Node node : this.nodesQueue) { queueJSON = new JSONObject(); queueJSON.put("node", node.getNodeName()); queueJSON.put("value", Math.round(node.getNodeValue())); queueJSONArray.add(queueJSON); } currentIteration.put("queue", queueJSONArray); Node toBeSpreadedNode = pickBestNode(); if (checkGoal(toBeSpreadedNode)) { return this.dst; } JSONObject spreadingNodeJSON = new JSONObject(); spreadingNodeJSON.put("name", toBeSpreadedNode.toString()); spreadingNodeJSON.put("value", toBeSpreadedNode.getNodeValue()); currentIteration.put("spreadingNode", spreadingNodeJSON); this.iterationJSONArray.add(currentIteration); List<Node> children = this.getChildren(toBeSpreadedNode); children = updateNodesCost(children); if (children.size() != 0) { //Remove The Parent Node and replace the children this.nodesQueue.remove(toBeSpreadedNode); this.nodesQueue.addAll(children); this.processedNodes.addAll(children); } else { this.nodesQueue.remove(toBeSpreadedNode); // A leaf that is not the destination } return null; }
From source file:net.nexxus.nntp.NntpArticleHeader.java
public String getPartsAsJSON() { if (multipart) { JSONArray partsArray = new JSONArray(); for (int x = 0; x < parts.length; x++) { // incomplete multiparts have null elements if (parts[x] != null) { JSONArray part = new JSONArray(); part.add(parts[x].getId()); part.add(parts[x].getMsgID()); partsArray.add(part);//from w w w . jav a 2 s. c o m } } return partsArray.toJSONString(); } return ""; }
From source file:com.bigml.histogram.ArrayCategoricalTarget.java
@Override @SuppressWarnings("unchecked") protected void addJSON(JSONArray binJSON, DecimalFormat format) { JSONObject counts = new JSONObject(); for (Entry<Object, Integer> categoryIndex : _indexMap.entrySet()) { Object category = categoryIndex.getKey(); int index = categoryIndex.getValue(); double count = _target[index]; counts.put(category, Utils.roundNumber(count, format)); }/*from ww w . ja v a2s . c om*/ binJSON.add(counts); }
From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java
/** * * Llama al delegate para Eliminar un Laboratorio * * @param codigo /*w w w.j av a2s .c o m*/ * @throws Exception */ public JSONArray Eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarTiposInformesVertimientos delete = new EliminarTiposInformesVertimientos(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:com.vizury.videocache.core.CampaignExecutor.java
@SuppressWarnings("unchecked") private void generateVideo(ProductDetail product) { JSONObject jReq = new JSONObject(); jReq.put("type", "command"); String jobID = threadId.toString() + "." + UUID.randomUUID().toString(); jReq.put("job_id", jobID); jReq.put("landing_page_url", product.getLandingPageUrl()); jReq.put("video_url", propertyMap.get("campaignProductListLocation")); jReq.put("campaign_id", campaignId); JSONArray products = new JSONArray(); // Add main product JSONObject productInfo = new JSONObject(); productInfo.put("img_url", product.getCdnUrl()); productInfo.put("pname", product.getProductName()); productInfo.put("pid", product.getProductId()); products.add(productInfo); // Add recommended products for (ProductDetail recProduct : product.getRecommendedProduct()) { JSONObject recProductInfo = new JSONObject(); recProductInfo.put("img_url", recProduct.getCdnUrl()); recProductInfo.put("pname", recProduct.getProductName()); recProductInfo.put("pid", recProduct.getProductId()); products.add(recProductInfo);// www .j a v a 2s. c o m } jReq.put("products", products); HttpRequest request = createJsonRequest(jReq.toJSONString()); Future<HttpResponse> slaveAckF = client.apply(request); slaveAckF.addEventListener(new FutureEventListener<HttpResponse>() { public void onFailure(Throwable e) { System.out.println(e.getCause() + " : " + e.getMessage()); } public void onSuccess(HttpResponse response) { System.out.println("[GeneratorMaster] Job ack received for job"); } }); }
From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java
/** * * Obtiene la informacion del tipo de Informe mediante un codigo y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray/* w w w . j av a2 s . com*/ * @throws SQLException */ public JSONArray getTipoInforme(int codigo) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiposInformesVertimiento seleccionar = new SeleccionarTiposInformesVertimiento(); ResultSet rst = seleccionar.getTipoInforme(codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } seleccionar.desconectar(); return jsonArray; }
From source file:modelo.ParametrizacionManagers.TiposInformeVertimientos.java
/** * * Obtiene la informacion del tipo de Informe de caracterizacin y Proceso Seco * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray/*from ww w . j ava 2 s . com*/ * @throws SQLException */ public JSONArray getTipoInformesPrincial() throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiposInformesVertimiento seleccionar = new SeleccionarTiposInformesVertimiento(); ResultSet rst = seleccionar.getTipoInformesPrincipal(); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArreglo = new JSONArray(); JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); seleccionar.desconectar(); return jsonArreglo; }
From source file:com.mobicage.rogerthat.registration.RegistrationWizard2.java
@SuppressWarnings("unchecked") @Override/* w ww . ja va 2 s.com*/ public void writePickle(DataOutput out) throws IOException { T.UI(); super.writePickle(out); boolean set = mCredentials != null; out.writeBoolean(set); if (set) { out.writeInt(mCredentials.getPickleClassVersion()); mCredentials.writePickle(out); } set = mEmail != null; out.writeBoolean(set); if (set) out.writeUTF(mEmail); out.writeLong(mTimestamp); out.writeUTF(mRegistrationId); out.writeBoolean(mInGoogleAuthenticationProcess); out.writeUTF(mInstallationId); out.writeUTF(mDeviceId); set = mBeaconRegions != null; out.writeBoolean(set); if (set) out.writeUTF(JSONValue.toJSONString(mBeaconRegions.toJSONMap())); set = mDetectedBeacons != null; out.writeBoolean(set); if (set) { JSONArray db1 = new JSONArray(); for (String db : mDetectedBeacons) { db1.add(db); } out.writeUTF(JSONValue.toJSONString(db1)); } }