List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.jilk.ros.rosbridge.implementation.JSON.java
private static JSONArray convertObjectToJSONArray(Object o) { JSONArray result = new JSONArray(); for (Field f : o.getClass().getFields()) { Object fieldObject = getFieldObject(f, o); if (fieldObject != null) { Object resultObject = convertElementToJSON(fieldObject); result.add(resultObject); }/*from w w w. j av a2 s . c o m*/ } return result; }
From source file:hoot.services.controllers.job.JobControllerBase.java
protected static JSONArray parseParams(String params) throws ParseException { JSONParser parser = new JSONParser(); JSONObject command = (JSONObject) parser.parse(params); JSONArray commandArgs = new JSONArray(); for (Object o : command.entrySet()) { Map.Entry<Object, Object> mEntry = (Map.Entry<Object, Object>) o; String key = (String) mEntry.getKey(); String val = (String) mEntry.getValue(); JSONObject arg = new JSONObject(); arg.put(key, val); commandArgs.add(arg); }/* ww w . j a v a 2s .com*/ return commandArgs; }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert from aggregate stats to JSONArray * /* w w w .j av a 2 s.com*/ * @param ofs * @return JSONArray of aggregate stats */ public static JSONArray toAggregateStat(List<OFStatistics> ofs) { JSONArray jsonArray = new JSONArray(); for (OFStatistics ofst : ofs) { OFAggregateStatisticsReply st = (OFAggregateStatisticsReply) ofst; JSONObject jsonObject = new JSONObject(); jsonObject.put("packet_count", st.getPacketCount()); jsonObject.put("flow_count", st.getFlowCount()); jsonArray.add(jsonObject); } return jsonArray; }
From source file:com.jilk.ros.rosbridge.implementation.JSON.java
private static JSONArray convertArrayToJSONArray(Object array) { JSONArray result = new JSONArray(); for (int i = 0; i < Array.getLength(array); i++) { Object elementObject = Array.get(array, i); if (elementObject != null) { Object resultObject = convertElementToJSON(elementObject); result.add(resultObject); }//from w w w . j av a 2s . c om } return result; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerMultiplesConvocatorias(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<ConvocatoriaEntity> convocatorias = new ArrayList<>(); convocatorias = CtrlUsuario.leerMultiplesConvocatorias(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // tamao y posicin response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (ConvocatoriaEntity convocatoria : convocatorias) { JSONObject obj = new JSONObject(); obj.put("id", convocatoria.getIdConvocatoria()); obj.put("titulo", convocatoria.getNombre()); list1.add(obj); }/*from w w w .j av a2s . c o m*/ out.print(list1); }
From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java
private static JSONObject processMultiLevelRequirementsElement(MultiLevelRequirements multiLevelRequirements) { JSONObject rootJSON = new JSONObject(); rootJSON.put("name", multiLevelRequirements.getName()); rootJSON.put("level", multiLevelRequirements.getLevel().toString()); rootJSON.put("type", "RequirementsLevel"); JSONArray requirementsBlocksArray = new JSONArray(); for (Requirements r : multiLevelRequirements.getUnitRequirements()) { JSONObject requirementsJSON = new JSONObject(); requirementsJSON.put("name", r.getName()); requirementsJSON.put("target", r.getTargetServiceID()); requirementsJSON.put("type", "RequirementsBlock"); JSONArray requirementsBlockRequirements = new JSONArray(); for (Requirement requirement : r.getRequirements()) { JSONObject requirementJSON = new JSONObject(); requirementJSON.put("type", "Requirement"); JSONArray conditionsArray = new JSONArray(); Metric metric = requirement.getMetric(); requirementJSON.put("metric", metric.getName() + "[" + metric.getMeasurementUnit() + "]"); for (Condition condition : requirement.getConditions()) { JSONObject conditionJSON = new JSONObject(); conditionJSON.put("name", condition.toString()); conditionJSON.put("type", "Condition"); conditionsArray.add(conditionJSON); }//from w ww. ja v a 2 s .co m requirementJSON.put("target", r.getTargetServiceID()); requirementJSON.put("children", conditionsArray); requirementsBlockRequirements.add(requirementJSON); } requirementsJSON.put("children", requirementsBlockRequirements); requirementsBlocksArray.add(requirementsJSON); } rootJSON.put("children", requirementsBlocksArray); return rootJSON; }
From source file:cn.vlabs.umt.ui.servlet.OauthTokenServlet.java
public static String getUserAsJSON(LoginNameInfo info, User user, String passwordType) { JSONObject object = new JSONObject(); object.put("umtId", user.getUmtId()); putStringToJSON(object, "truename", user.getTrueName()); putStringToJSON(object, "type", user.getType()); putStringToJSON(object, "cstnetId", user.getCstnetId()); putStringToJSON(object, "cstnetIdStatus", info.getStatus()); putStringToJSON(object, "securityEmail", user.getSecurityEmail()); putStringToJSON(object, "passwordType", passwordType); String[] emails = user.getSecondaryEmails(); if (emails != null && emails.length > 0) { JSONArray ar = new JSONArray(); for (int i = 0; i < emails.length; i++) { ar.add(emails[i]); }//from w w w . ja va 2 s .com object.put("secondaryEmails", ar); } return object.toJSONString(); }
From source file:com.healthcit.analytics.utils.ExcelExportUtils.java
@SuppressWarnings("unchecked") public static void streamVisualizationDataAsExcelFormat(OutputStream out, JSONObject data) { // Get the array of columns JSONArray jsonColumnArray = (JSONArray) data.get(COLUMNS_JSON_KEY); String[] excelColumnArray = new String[jsonColumnArray.size()]; for (int index = 0; index < excelColumnArray.length; ++index) { excelColumnArray[index] = (String) ((JSONObject) jsonColumnArray.get(index)).get(LABEL_JSON_KEY); }// ww w . j a va 2 s. co m // Get the array of rows JSONArray jsonRowArray = (JSONArray) data.get(ROWS_JSON_KEY); JSONArray excelRowArray = new JSONArray(); Iterator<JSONObject> jsonRowIterator = jsonRowArray.iterator(); while (jsonRowIterator.hasNext()) { JSONArray rowCell = (JSONArray) jsonRowIterator.next().get(ROWCELL_JSON_KEY); JSONObject excelRowObj = new JSONObject(); for (int index = 0; index < rowCell.size(); ++index) { excelRowObj.put(excelColumnArray[index], ((JSONObject) rowCell.get(index)).get(ROWCELLVALUE_JSON_KEY)); } excelRowArray.add(excelRowObj); } // build the Excel outputstream Json2Excel.build(out, excelRowArray.toJSONString(), excelColumnArray); }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static String buildJSONString(Set<Autocompletion_Trie.AutocompleteElement> autocomplete) throws IOException { JSONArray jsonResults = new JSONArray(); StringWriter json = new StringWriter(); for (Autocompletion_Trie.AutocompleteElement result : autocomplete) { JSONObject jsonResult = new JSONObject(); jsonResult.put("uri", result.id); jsonResult.put("label", result.label); jsonResults.add(jsonResult); }//from w w w . j a v a 2 s.c o m JSONObject finalJSONresult = new JSONObject(); finalJSONresult.put("results", jsonResults); finalJSONresult.writeJSONString(json); return json.toString(); }
From source file:net.sourceforge.fenixedu.webServices.jersey.services.JerseyServices.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from w w w.j a v a 2s. co m*/ @Path("readAllStudentsInfoForJobBank") public static String readAllStudentsInfoForJobBank() { ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); Set<Registration> registrations = new HashSet<Registration>(); LocalDate today = new LocalDate(); for (Registration registration : Bennu.getInstance().getRegistrationsSet()) { if (registration.hasAnyActiveState(currentExecutionYear) && registration.isBolonha() && !registration.getDegreeType().equals(DegreeType.EMPTY)) { registrations.add(registration); } } for (ConclusionProcess conclusionProcess : Bennu.getInstance().getConclusionProcessesSet()) { if (conclusionProcess.getConclusionDate() != null && !conclusionProcess.getConclusionDate().plusYears(1).isBefore(today)) { registrations.add(conclusionProcess.getRegistration()); } } JSONArray infos = new JSONArray(); for (Registration registration : registrations) { infos.add(getStudentInfoForJobBank(registration)); } return infos.toJSONString(); }