List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:modelo.ParametrizacionManagers.DocumentacionRequerida.java
/** * //from w w w . j a va 2 s .c o m * Obtiene la informacion de la documentacion requerida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getDocumentacionRequerida(String descripcion, String tipoInforme) throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarDocumentacionRequerida select = new SeleccionarDocumentacionRequerida(); ResultSet rset = select.getDocumentacionRequeridas(descripcion, tipoInforme); //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("CODIGO")); jsonObject.put("descripcion", rset.getString("DESCRIPCION")); jsonObject.put("tipoInforme", rset.getString("TIPO_INFORME")); jsonObject.put("codTipoInforme", rset.getString("COD_TIPO_INFORME")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); } jsonArreglo.add(jsonArray); select.desconectar(); return jsonArreglo; }
From source file:modelo.ProcesoVertimientosManagers.ProgramarMonitoreo.java
public JSONArray obtenerPuntosMonitoreo(String puntoMonitoreo) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarMonitoreos select = new SeleccionarMonitoreos(); ResultSet rset = select.obtenerPuntosMonitoreo(puntoMonitoreo); //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("actividadEconomica", rset.getString("FK_ACTIVIDAD_ECONOMICA")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }//w ww. j a v a 2s. com jsonArreglo.add(jsonArray); select.desconectar(); return jsonArreglo; }
From source file:com.ocs.indaba.controlpanel.controller.proj.NotificationController.java
public String getAllOptions() { JSONObject root = new JSONObject(); try {/* w w w . j a va 2s. c om*/ logger.debug("\nEnter getAllOptions"); printURLRequestQuery(); int projId = StringUtils.str2int(request.getParameter(PARAM_PROJECT_ID)); List<Language> languages = languageSrvc.getAllLanguages(); JSONArray langArr = new JSONArray(); root.put("languages", langArr); if (languages != null && !languages.isEmpty()) { for (Language l : languages) { JSONObject jsonObj = new JSONObject(); jsonObj.put("id", l.getId()); jsonObj.put("name", l.getLanguageDesc()); langArr.add(jsonObj); } } List<Role> roles = roleSrvc.getAllRoles(projId); JSONArray roleArr = new JSONArray(); root.put("roles", roleArr); if (roles != null && !roles.isEmpty()) { JSONObject jsonObj = new JSONObject(); jsonObj.put("id", 0); jsonObj.put("name", "DEFAULT"); roleArr.add(jsonObj); for (Role r : roles) { jsonObj = new JSONObject(); jsonObj.put("id", r.getId()); jsonObj.put("name", r.getName()); roleArr.add(jsonObj); } } List<NotificationType> nTypes = notificationItemSrvc.getProjectCustomizableNotificationTypes(); JSONArray typeArr = new JSONArray(); root.put("ntypes", typeArr); if (nTypes != null && !nTypes.isEmpty()) { for (NotificationType nt : nTypes) { JSONObject jsonObj = new JSONObject(); jsonObj.put("id", nt.getId()); jsonObj.put("name", nt.getName()); jsonObj.put("category", nt.getCategory()); typeArr.add(jsonObj); } } List<Tokenset> tklist = notificationItemSrvc.getTokensets(); JSONArray categoryArr = new JSONArray(); root.put("categories", categoryArr); if (tklist != null && !tklist.isEmpty()) { for (Tokenset tk : tklist) { JSONObject jsonObj = new JSONObject(); jsonObj.put("id", tk.getId()); jsonObj.put("tokens", tk.getTokens()); jsonObj.put("category", tk.getCatgeory()); categoryArr.add(jsonObj); } } super.sendResponseJson(root); return RESULT_EMPTY; } finally { logger.debug("\nExit getAllOptions" + root + "\n"); } }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Test public void updateKnownHostsWorks() throws Exception { Config cfg = new Config("/path/to/nothing"); assertTrue(cfg.getPeerConfigs().isEmpty()); JSONObject peer0 = new JSONObject(); JSONArray hosts = new JSONArray(); JSONArray pubAllow = new JSONArray(); JSONArray subAllow = new JSONArray(); peer0.put("hosts", hosts); peer0.put("publishAllow", pubAllow); peer0.put("subscribeAllow", subAllow); assertTrue(cfg.getPeerConfigs().isEmpty()); cfg.updateKnownHosts(peer0);/*from w w w. j av a2 s. c o m*/ JSONObject peer1 = new JSONObject(); hosts.add("192.168.1.1"); peer1.put("hosts", hosts); pubAllow.add("audit"); peer1.put("publishAllow", pubAllow); subAllow.add("log"); peer1.put("subscribeAllow", subAllow); cfg.updateKnownHosts(peer1); JSONObject peer2 = new JSONObject(); hosts.clear(); hosts.add("192.168.1.2"); peer2.put("hosts", hosts); pubAllow.clear(); pubAllow.add("log"); peer2.put("publishAllow", pubAllow); subAllow.clear(); subAllow.add("audit"); peer2.put("subscribeAllow", subAllow); Map<InetAddress, PeerConfig> peerCfgs = cfg.getPeerConfigs(); InetAddress addr1 = InetAddresses.forString("192.168.1.1"); assertTrue(peerCfgs.containsKey(addr1)); assertTrue( peerCfgs.get(InetAddresses.forString("192.168.1.1")).getPublishAllow().contains(RecordType.Audit)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.1")).getPublishAllow() .contains(RecordType.Journal)); assertFalse( peerCfgs.get(InetAddresses.forString("192.168.1.1")).getPublishAllow().contains(RecordType.Log)); assertTrue( peerCfgs.get(InetAddresses.forString("192.168.1.1")).getSubscribeAllow().contains(RecordType.Log)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.1")).getSubscribeAllow() .contains(RecordType.Audit)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.1")).getSubscribeAllow() .contains(RecordType.Journal)); cfg.updateKnownHosts(peer2); peerCfgs = cfg.getPeerConfigs(); assertTrue(peerCfgs.containsKey(InetAddresses.forString("192.168.1.2"))); assertFalse( peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow().contains(RecordType.Audit)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow() .contains(RecordType.Journal)); assertTrue(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow().contains(RecordType.Log)); assertFalse( peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow().contains(RecordType.Log)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow() .contains(RecordType.Journal)); assertTrue(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow() .contains(RecordType.Audit)); peer2.remove("subscribeAllow"); JSONArray subAllows = new JSONArray(); subAllows.add("journal"); peer2.put("subscribeAllow", subAllows); cfg.updateKnownHosts(peer2); peerCfgs = cfg.getPeerConfigs(); assertTrue(peerCfgs.containsKey(InetAddresses.forString("192.168.1.2"))); assertFalse( peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow().contains(RecordType.Audit)); assertFalse(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow() .contains(RecordType.Journal)); assertTrue(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getPublishAllow().contains(RecordType.Log)); assertFalse( peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow().contains(RecordType.Log)); assertTrue(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow() .contains(RecordType.Journal)); assertTrue(peerCfgs.get(InetAddresses.forString("192.168.1.2")).getSubscribeAllow() .contains(RecordType.Audit)); }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert a list of flows to JSONArray/* w w w. j av a 2s.c o m*/ * @param ofs * @return JSONArray of flows */ public static JSONArray toFlowStat(List<OFStatistics> ofs) { JSONArray jsonArray = new JSONArray(); for (OFStatistics ofst : ofs) { OFFlowStatisticsReply st = (OFFlowStatisticsReply) ofst; JSONObject jsonObject = new JSONObject(); String[] a = st.getActions().toString().split("port="); String c; c = st.getActions().toString(); if (a.length == 1) { c = st.getActions().toString(); } else { String[] b = a[1].split(","); c = b[0]; } // parse the output String outputString = ""; try { Pattern pattern = Pattern.compile("port=\\w*"); Matcher matcher = pattern.matcher(st.getActions().toString()); while (matcher.find()) { outputString += matcher.group().split("=")[1] + ","; } } catch (PatternSyntaxException pse) { outputString = "malformed"; } if (outputString.length() == 0) { outputString = "DROP,"; } jsonObject.put("actions", outputString.substring(0, outputString.length() - 1)); jsonObject.put("hard_timeout", st.getHardTimeout()); jsonObject.put("idle_timeout", st.getIdleTimeout()); jsonObject.put("match", st.getMatch().toString()); jsonObject.put("priority", st.getPriority()); jsonObject.put("packet_count", st.getPacketCount()); jsonObject.put("byte_count", st.getByteCount()); jsonObject.put("table_id", st.getTableId()); jsonArray.add(jsonObject); } if (jsonArray.size() == 0) { JSONObject jso = new JSONObject(); jso.put("data", "nono"); } return jsonArray; }
From source file:com.bigml.histogram.Histogram.java
@SuppressWarnings("unchecked") public JSONArray toJSON(DecimalFormat format) { JSONArray bins = new JSONArray(); for (Bin<T> bin : getBins()) { bins.add(bin.toJSON(format)); }/*w w w .j av a2s.c o m*/ return bins; }
From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java
public JSONArray pullObjectsByIndexesToJSON(Expression... indexqueryexpressions) throws ConnectionException, ParseException { List<T> values = pullObjectsByIndexes(indexqueryexpressions); JSONArray ja = new JSONArray(); JSONParser jp = new JSONParser(); for (int pos = 0; pos < values.size(); pos++) { jp.reset();/*from w w w . j av a2 s . com*/ ja.add(jp.parse((new Gson()).toJson(values.get(pos)))); } return ja; }
From source file:modelo.ProcesoVertimientosManagers.ManejoLodos.java
public JSONArray getArchivosLodos(int codigo) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarLodos select = new SeleccionarLodos(); ResultSet rset = select.getArchivosLodos(codigo); //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("CODIGO")); String nombreArchivo = (rset.getString("NOMBRE_ARCHIVO")).replace("\\", ""); jsonObject.put("nombreArchivo", nombreArchivo); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }/* ww w . ja v a 2 s . c o m*/ jsonArreglo.add(jsonArray); select.desconectar(); return jsonArreglo; }
From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java
public final Shops addBuy(String shopName, String cost, Player player) { try {/* www . ja va 2s . c o m*/ String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json"))); JSONParser parser = new JSONParser(); Object obj = parser.parse(configTable); JSONObject jsonObj = (JSONObject) obj; JSONObject shopObj = (JSONObject) jsonObj.get(shopName); // Make sure the shop exists if (shopObj == null) { player.sendMessage("\u00a76That shop does not exist!"); return this; } String newItem = player.getItemInHand().getType().name(); Bukkit.getLogger() .info("Player \"" + player.getDisplayName() + "\" added " + newItem + " to shop " + shopName); JSONArray shopItems = (JSONArray) shopObj.get("ShopItems"); shopItems.add(newItem + ":buy:" + player.getItemInHand().getDurability()); shopObj.put("ShopItems", shopItems); JSONObject itemStub = new JSONObject(); itemStub.put("amount", Integer.toString(player.getItemInHand().getAmount())); itemStub.put("price", cost); itemStub.put("type", "buy"); itemStub.put("durability", "" + player.getItemInHand().getDurability()); shopObj.put(newItem + ":buy:" + player.getItemInHand().getDurability(), itemStub); jsonObj.put(shopName, shopObj); // Update Shops.json FileWriter shopsJSON = new FileWriter("./plugins/mcDropShop/Shops.json"); shopsJSON.write(jsonObj.toJSONString()); shopsJSON.flush(); shopsJSON.close(); player.sendMessage("\u00a7aShop updated!"); return this; } catch (ParseException e) { Bukkit.getLogger().warning("[mcDropShop] Caught ParseException in addBuy()"); e.printStackTrace(); } catch (FileNotFoundException e) { Bukkit.getLogger().warning("[mcDropShop] Could not find ./plugins/mcDropShop/Shops.json"); e.printStackTrace(); } catch (IOException e) { Bukkit.getLogger().warning("[mcDropShop] Caught IOException in addBuy()"); e.printStackTrace(); } return this; }
From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java
public final Shops addSell(String shopName, String cost, Player player) { try {/*from w w w. j a va2s .c o m*/ String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json"))); JSONParser parser = new JSONParser(); Object obj = parser.parse(configTable); JSONObject jsonObj = (JSONObject) obj; JSONObject shopObj = (JSONObject) jsonObj.get(shopName); // Make sure the shop exists if (shopObj == null) { player.sendMessage("\u00a76That shop does not exist!"); return this; } String newItem = player.getItemInHand().getType().name(); Bukkit.getLogger() .info("Player \"" + player.getDisplayName() + "\" added " + newItem + " to shop " + shopName); JSONArray shopItems = (JSONArray) shopObj.get("ShopItems"); shopItems.add(newItem + ":sell:" + player.getItemInHand().getDurability()); shopObj.put("ShopItems", shopItems); JSONObject itemStub = new JSONObject(); itemStub.put("amount", Integer.toString(player.getItemInHand().getAmount())); itemStub.put("price", cost); itemStub.put("type", "sell"); itemStub.put("durability", "" + player.getItemInHand().getDurability()); shopObj.put(newItem + ":sell:" + player.getItemInHand().getDurability(), itemStub); jsonObj.put(shopName, shopObj); // Update Shops.json FileWriter shopsJSON = new FileWriter("./plugins/mcDropShop/Shops.json"); shopsJSON.write(jsonObj.toJSONString()); shopsJSON.flush(); shopsJSON.close(); player.sendMessage("\u00a7aShop updated!"); return this; } catch (ParseException e) { Bukkit.getLogger().warning("[mcDropShop] Caught ParseException in addSell()"); e.printStackTrace(); } catch (FileNotFoundException e) { Bukkit.getLogger().warning("[mcDropShop] Could not find ./plugins/mcDropShop/Shops.json"); e.printStackTrace(); } catch (IOException e) { Bukkit.getLogger().warning("[mcDropShop] Caught IOException in addSell()"); e.printStackTrace(); } return this; }