List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java
public static JSONArray fullestoArray(String[] instance_group_keys, Jedis jedis) { JSONArray result = new JSONArray(); JSONObject info = new JSONObject(); for (int i = 0; i < instance_group_keys.length; ++i) { String[] instancesOfGroup = jedis.smembers(instance_group_keys[i]).toArray(new String[0]); for (int j = 0; j < instancesOfGroup.length; ++j) { info = new JSONObject(); info.put("name", instancesOfGroup[j]); result.add(info); }/*w ww .j av a2 s.co m*/ } return result; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void iniciarWSC(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = CtrlAdmin.iniciarWSC(Integer.parseInt(request.getParameter("1")), //id evento Integer.parseInt(request.getParameter("2")), //tamao tabla Integer.parseInt(request.getParameter("3"))//pagina ); // parameter 1: documentoDocente param2: idTaller 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); }// w w w . ja va 2 s .co m out.print(list1); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarUsuariosEnTallerId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("3")), Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("1"))); 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); }/* w w w . j av a2 s . c om*/ out.print(list1); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarDocentesEnTallerId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("3"))); 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 va2s .c o m out.print(list1); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarUsuariosEnConvocatoriaId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnConvocatoria(Integer.parseInt(request.getParameter("3")), //id evento Integer.parseInt(request.getParameter("2")), //tamao tabla Integer.parseInt(request.getParameter("1"))//pagina );//from www . ja va2 s . c o m 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); } out.print(list1); }
From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java
public static String convertTOJSON(MultiLevelRequirements levelRequirements) { if (levelRequirements == null) { return "{nothing}"; }//from w w w . j a va 2 s . c o m JSONObject root = new JSONObject(); //diff is that in some cases (e.g. condition), name is displayName root.put("name", levelRequirements.getName()); root.put("realName", levelRequirements.getName()); root.put("type", "" + levelRequirements.getLevel()); //traverse recursive XML tree List<JSONObject> jsonObjects = new ArrayList<>(); List<MultiLevelRequirements> reqsList = new ArrayList<>(); reqsList.add(levelRequirements); jsonObjects.add(root); while (!reqsList.isEmpty()) { JSONObject obj = jsonObjects.remove(0); MultiLevelRequirements reqs = reqsList.remove(0); JSONArray children = new JSONArray(); for (MultiLevelRequirements childReqs : reqs.getContainedElements()) { JSONObject child = new JSONObject(); child.put("name", childReqs.getName()); child.put("realName", childReqs.getName()); child.put("type", "" + childReqs.getLevel()); children.add(child); reqsList.add(childReqs); jsonObjects.add(child); } //add strategies for (Strategy strategy : reqs.getOptimizationStrategies()) { JSONObject strategyJSON = new JSONObject(); strategyJSON.put("name", "" + strategy.getStrategyCategory().toString()); strategyJSON.put("realName", "" + strategy.getStrategyCategory().toString()); strategyJSON.put("type", "Strategy"); children.add(strategyJSON); } // JSONArray unitReqs = new JSONArray(); for (Requirements requirements : reqs.getUnitRequirements()) { JSONObject child = new JSONObject(); child.put("name", requirements.getName()); child.put("realName", requirements.getName()); child.put("type", "RequirementsBlock"); children.add(child); JSONArray requirementsJSON = new JSONArray(); for (Requirement requirement : requirements.getRequirements()) { JSONObject requirementJSON = new JSONObject(); requirementJSON.put("name", requirement.getName()); requirementJSON.put("realName", requirement.getName()); requirementJSON.put("type", "Requirement"); //put individual conditions JSONArray conditions = new JSONArray(); for (Condition condition : requirement.getConditions()) { JSONObject conditionJSON = new JSONObject(); conditionJSON.put("name", "MUST BE " + condition.toString()); conditionJSON.put("type", "Condition"); conditionJSON.put("realName", "" + condition.getType()); conditions.add(conditionJSON); } requirementJSON.put("children", conditions); requirementsJSON.add(requirementJSON); } child.put("children", requirementsJSON); } obj.put("children", children); } return root.toJSONString(); }
From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java
public static String getStates(String statesFilePath) throws ParserConfigurationException, IOException, SAXException { JSONObject statesFeatureCollection = new JSONObject(); statesFeatureCollection.put("type", "FeatureCollection"); JSONArray features = new JSONArray(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/*from w w w . j a va 2 s . com*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document dom = documentBuilder.parse(new FileInputStream(new File(statesFilePath))); Element docElement = dom.getDocumentElement(); NodeList states = docElement.getElementsByTagName("state"); for (int i = 0; i < states.getLength(); i++) { Node state = states.item(i); JSONObject stateObj = new JSONObject(); stateObj.put("type", "Feature"); JSONObject geometry = new JSONObject(); geometry.put("type", "Polygon"); JSONArray coordinates = new JSONArray(); JSONArray coordinateSub = new JSONArray(); NodeList points = ((Element) state).getElementsByTagName("point"); for (int j = 0; j < points.getLength(); j++) { Node point = points.item(j); JSONArray pointObj = new JSONArray(); float lat = Float.parseFloat(((Element) point).getAttribute("lat")); float lng = Float.parseFloat(((Element) point).getAttribute("lng")); double trLng = lng * 20037508.34 / 180; double trLat = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); pointObj.add(lng); pointObj.add(lat); coordinateSub.add(pointObj); } geometry.put("coordinates", coordinates); coordinates.add(coordinateSub); stateObj.put("geometry", geometry); JSONObject name = new JSONObject(); name.put("Name", ((Element) state).getAttribute("name")); name.put("colour", "#FFF901"); stateObj.put("properties", name); features.add(stateObj); } statesFeatureCollection.put("features", features); return statesFeatureCollection.toJSONString(); } catch (ParserConfigurationException e) { log.error("Error while processing states.xml.", e); throw e; } catch (FileNotFoundException e) { log.error("Error while processing states.xml.", e); throw e; } catch (SAXException e) { log.error("Error while processing states.xml.", e); throw e; } catch (IOException e) { log.error("Error while processing states.xml.", e); throw e; } }
From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java
@SuppressWarnings("unchecked") private static JSONArray serializeSemanticTags(List<SemanticTag> tags) { JSONArray jsonArray = new JSONArray(); for (SemanticTag t : tags) { JSONObject jsonObj = new JSONObject(); jsonObj.put(KEY_TAG_URI, t.getURI()); jsonObj.put(KEY_TAG_LABEL, t.getPrimaryLabel()); jsonObj.put(KEY_TAG_DESCRIPTION, t.getPrimaryDescription()); jsonObj.put(KEY_TAG_LANG, t.getPrimaryLanguage()); jsonObj.put(KEY_TAG_TYPE, t.getType()); JSONArray altLabels = new JSONArray(); for (PlainLiteral p : t.getAlternativeLabels()) { JSONObject label = new JSONObject(); label.put(KEY_ALT_LABEL_LANG, p.getLanguage()); label.put(KEY_ALT_LABEL_VAL, p.getValue()); altLabels.add(label); }/*from ww w. ja v a2s .c o m*/ jsonObj.put(KEY_TAG_ALT_LABELS, altLabels); jsonArray.add(jsonObj); } return jsonArray; }
From source file:cloudclient.Client.java
@SuppressWarnings("unchecked") public static void batchSendTask(PrintWriter out, String workload) throws FileNotFoundException, MalformedURLException { FileInputStream input = new FileInputStream(workload); BufferedReader bin = new BufferedReader(new InputStreamReader(input)); // Get task from workload file String line;//from www .j a va2 s. c o m // String sleepLength; String id; int count = 0; final int batchSize = 10; try { //Get client public IP String ip = getIP(); //System.out.println(ip); //JSON object Array JSONArray taskList = new JSONArray(); while ((line = bin.readLine()) != null) { //sleepLength = line.replaceAll("[^0-9]", ""); //System.out.println(sleepLength); count++; id = ip + ":" + count; JSONObject task = new JSONObject(); task.put("task_id", id); task.put("task", line); taskList.add(task); if (taskList.size() == batchSize) { out.println(taskList.toString()); taskList.clear(); } } //System.out.println(taskList.toString()); if (!taskList.isEmpty()) { out.println(taskList.toString()); taskList.clear(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerMultiplesTalleres(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<TallerEntity> talleres = new ArrayList<>(); talleres = CtrlUsuario.leerMultiplesTalleres(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // posicin y tamao response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); System.out.println("Talleres: " + talleres.size()); JSONArray list1 = new JSONArray(); for (TallerEntity taller : talleres) { JSONObject obj = new JSONObject(); obj.put("id", taller.getIdTaller()); obj.put("titulo", taller.getNombre()); list1.add(obj); }//from w w w . j a v a2 s . co m out.print(list1); }