List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:org.kitodo.data.index.elasticsearch.type.TemplateType.java
@SuppressWarnings("unchecked") @Override/*from w w w.java2s . c om*/ public HttpEntity createDocument(Template template) { LinkedHashMap<String, String> orderedTemplateMap = new LinkedHashMap<>(); String process = template.getProcess() != null ? template.getProcess().getId().toString() : "null"; orderedTemplateMap.put("process", process); JSONObject processObject = new JSONObject(orderedTemplateMap); JSONArray properties = new JSONArray(); List<TemplateProperty> templateProperties = template.getProperties(); for (TemplateProperty property : templateProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } processObject.put("properties", properties); return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:amulet.resourceprofiler.JSONResourceReader.java
public JSONResourceReader() { deviceInformation = new DeviceInfo(); steadyStateInformation = new SteadyStateInfo(); apiInfo = new JSONArray(); energyParameters = new LinkedHashMap<String, EnergyParam>(); }
From source file:org.kitodo.data.index.elasticsearch.type.WorkpieceType.java
@SuppressWarnings("unchecked") @Override// w ww . ja v a 2 s .c o m public HttpEntity createDocument(Workpiece workpiece) { LinkedHashMap<String, String> orderedWorkpieceMap = new LinkedHashMap<>(); String process = workpiece.getProcess() != null ? workpiece.getProcess().getId().toString() : "null"; orderedWorkpieceMap.put("process", process); JSONObject processObject = new JSONObject(orderedWorkpieceMap); JSONArray properties = new JSONArray(); List<WorkpieceProperty> workpieceProperties = workpiece.getProperties(); for (WorkpieceProperty property : workpieceProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } processObject.put("properties", properties); return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:modelo.ParametrizacionManagers.TiemposBackup.java
/** * //from w w w . j a va2 s . com * Obtiene la informacion de las unidades de medida y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray * @throws SQLException */ public JSONArray getTiemposBackup() throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTiemposBackup select = new SeleccionarTiemposBackup(); ResultSet rset = select.getTiemposBackup(); //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("tiempo", rset.getString("DIAS_BACKUP")); //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:com.endgame.binarypig.util.JsonUtilTest.java
public void testIt() { JsonUtil ju = new JsonUtil(); JSONArray list = new JSONArray(); list.add("1"); list.add("2"); list.add("3"); JSONObject value = new JSONObject(); value.put("name", "Jason"); value.put("null", null); value.put("num", 7); value.put("bool", true); value.put("list", list); Object wrapped = ju.wrap(value); assertTrue(wrapped instanceof Map); Map map = (Map) wrapped; assertEquals(map.get("name"), "Jason"); assertNull(map.get("null")); assertEquals(map.get("num"), "7"); assertEquals(map.get("bool"), "true"); List<Tuple> tuples = Arrays.asList(TupleFactory.getInstance().newTuple((Object) "1"), TupleFactory.getInstance().newTuple((Object) "2"), TupleFactory.getInstance().newTuple((Object) "3")); assertEquals(map.get("list"), new NonSpillableDataBag(tuples)); }
From source file:di.uniba.it.tee2.api.v1.SearchService.java
@GET public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery, @QueryParam("n") int n) { try {/*from ww w .jav a 2s.c o m*/ SearchServiceWrapper instance = SearchServiceWrapper.getInstance( ServerConfig.getInstance().getProperty("search.language"), ServerConfig.getInstance().getProperty("search.index")); List<SearchResult> search = instance.getSearch().search(query, timeQuery, n); JSONObject json = new JSONObject(); json.put("size", search.size()); JSONArray results = new JSONArray(); for (SearchResult sr : search) { results.add(sr.toJSON()); } json.put("results", results); return Response.ok(json.toString()).build(); } catch (Exception ex) { Logger.getLogger(SearchService.class.getName()).log(Level.SEVERE, null, ex); return Response.serverError().build(); } }
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 ww . j a va 2s .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: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 ww w. ja v a 2 s. c om 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:di.uniba.it.tee2.api.v1.NaturalSearchService.java
@GET public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery, @QueryParam("n") int n) { try {/* ww w .ja v a 2s. c o m*/ SearchServiceWrapper instance = SearchServiceWrapper.getInstance( ServerConfig.getInstance().getProperty("search.language"), ServerConfig.getInstance().getProperty("search.index")); List<SearchResult> search = instance.getSearch().naturalSearch(query, timeQuery, n); JSONObject json = new JSONObject(); json.put("size", search.size()); JSONArray results = new JSONArray(); for (SearchResult sr : search) { results.add(sr.toJSON()); } json.put("results", results); return Response.ok(json.toString()).build(); } catch (Exception ex) { Logger.getLogger(NaturalSearchService.class.getName()).log(Level.SEVERE, null, ex); return Response.serverError().build(); } }
From source file:fr.nantes.web.quizz.servlets.Quizzquestions.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONArray quizzquestions = new JSONArray(); Questionnaire questionnaire = new Questionnaire(); quizzquestions = questionnaire.toJson(); response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(quizzquestions);// ww w . jav a 2s . c o m } }