List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.dubture.symfony.core.util.JsonUtils.java
@SuppressWarnings("unchecked") public static String createDefaultSyntheticServices() { JSONArray data = new JSONArray(); JSONObject request = new JSONObject(); request.put(Service.NAME, "request"); request.put(Service.CLASS, "Symfony\\Component\\HttpFoundation\\Request"); data.add(request); return data.toString(); }
From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java
public static String convertToJSON(MultiLevelRequirements multiLevelRequirements) { //traverse the tree to do the JSON properly List<JSONObject> jsontree = new ArrayList<JSONObject>(); List<MultiLevelRequirements> multiLevelRequirementsTree = new ArrayList<MultiLevelRequirements>(); JSONObject root = processMultiLevelRequirementsElement(multiLevelRequirements); jsontree.add(root);//from w w w.j av a2 s .c o m multiLevelRequirementsTree.add(multiLevelRequirements); //traverse the tree in a DFS manner while (!multiLevelRequirementsTree.isEmpty()) { MultiLevelRequirements currentlyProcessed = multiLevelRequirementsTree.remove(0); JSONObject currentlyProcessedJSONObject = jsontree.remove(0); JSONArray childrenArray = new JSONArray(); //process children for (MultiLevelRequirements child : currentlyProcessed.getContainedElements()) { JSONObject childJSON = processMultiLevelRequirementsElement(child); childrenArray.add(childJSON); //next to process are children jsontree.add(childJSON); multiLevelRequirementsTree.add(child); } if (currentlyProcessedJSONObject.containsKey("children")) { JSONArray array = (JSONArray) currentlyProcessedJSONObject.get("children"); array.addAll(childrenArray); } else { currentlyProcessedJSONObject.put("children", childrenArray); } } return root.toJSONString(); }
From source file:ListOfCitys.CityList.java
private static String getCountryName(String zone) throws IOException { String[] arry = zone.split(";"); //EU;DE zone = arry[1];//from ww w . j a va2 s . com String[] locales = Locale.getISOCountries(); String countryName = ""; JSONArray countryWithCities = new JSONArray(); Map<String, List<String>> countryWithCityNames = new HashMap<>(); for (String countryCode : locales) { Locale obj = new Locale("", countryCode); System.out .println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry()); countryWithCities.add(getCityNameForCountry(obj.getCountry(), countryCode)); if (obj.getCountry().equalsIgnoreCase(zone)) { countryName = obj.getDisplayCountry(); break; } } System.out.println("-----json array --- " + countryWithCities.toJSONString()); try (FileWriter file = new FileWriter("test.json")) { file.write(countryWithCities.toJSONString()); } return countryName; }
From source file:com.mum.edu.cs472.dictServlet.java
public static JSONArray convertToJSON(ResultSet resultSet) throws Exception { JSONArray jsonArray = new JSONArray(); while (resultSet.next()) { int total_rows = resultSet.getMetaData().getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 0; i < total_rows; i++) { obj.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1)); jsonArray.add(obj); }//from w ww .jav a2 s .com } return jsonArray; }
From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java
public static String convertTOJSON(List<Metric> metrics) { JSONArray children = new JSONArray(); for (Metric m : metrics) { JSONObject metricJSON = new JSONObject(); metricJSON.put("name", m.getName()); metricJSON.put("unit", m.getMeasurementUnit()); metricJSON.put("type", "" + m.getType()); children.add(metricJSON); }// www. j av a 2 s.c om return children.toJSONString(); }
From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java
public static void saveList(Collection<GraphOperation> ops, File f, Map<String, Double> queryNodes) throws IOException { FileWriter wr = new FileWriter(f); JSONArray arr = new JSONArray(); for (GraphOperation op : ops) { JSONObject obj = op.toJSON();// ww w .j av a2 s. c o m JSONObject mark = new JSONObject(); mark.put("class", op.getClass().getName()); mark.put("object", obj); arr.add(mark); } JSONArray noi = new JSONArray(); for (String z : queryNodes.keySet()) { JSONObject jo = new JSONObject(); jo.put("node", z); Double val = queryNodes.get(z); jo.put("value", val); noi.add(jo); } arr.add(noi); arr.writeJSONString(wr); wr.close(); }
From source file:msuresh.raftdistdb.RaftCluster.java
private static void SetupServerAddress(int numReplicas, JSONObject[] lis, List<Address> members, JSONArray arr) { for (int i = 0; i < numReplicas; i++) { Address addr = new Address("localhost", portId++); lis[i] = new JSONObject(); lis[i].put("address", addr.host()); lis[i].put("port", addr.port()); members.add(addr);/*from w w w . j av a2 s. c o m*/ arr.add(lis[i]); } }
From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java
public static String getPathwayGeneSymbols(String pathwayName) { List<String> geneSymbols = LookupManager.getPathwayGeneSymbols(pathwayName); JSONArray symbols = new JSONArray(); for (String symbol : geneSymbols) { symbols.add(symbol); }// w w w . jav a 2s . c o m return "(" + symbols.toString() + ")"; }
From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java
public static String getRBTFeatures() { String jfeats = ""; //get the features from the external props String feats = System.getProperty("rembrandt.feedback.features"); List<String> f = Arrays.asList(feats.split(",")); JSONArray fs = new JSONArray(); for (String s : f) { s = s.trim();// www . j av a 2 s. c o m fs.add(s); } if (fs.size() > 0) { jfeats = fs.toString(); } return jfeats; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuariosMultiplesId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.leerMultiplesUsuarios(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // id del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (UsuarioEntity usuario : usuarios) { JSONObject obj = new JSONObject(); obj.put("id", usuario.getIdUsuario()); obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos()); list1.add(obj); }/*from w w w.j a v a 2s . com*/ out.print(list1); }