List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.erbjuder.logger.server.entity.impl.Graph.java
public JSONObject toJSON() { JSONArray nodeList = new JSONArray(); for (Node node : getNodes()) { nodeList.add(node.toJSON()); }//from w ww .j av a 2 s .co m JSONArray edgeList = new JSONArray(); for (Edge edge : getEdges()) { edgeList.add(edge.toJSON()); } JSONObject json = new JSONObject(); json.put("id", getId()); json.put("flowConfigurationId", this.getGlobalFlowConfiguration() == null ? "null" : this.getGlobalFlowConfiguration().getId()); json.put("nodes", nodeList); json.put("edges", edgeList); return json; }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static String jsonifyObirsResults(List<ObirsResult> results, IndexerJSON indexer, Map<URI, String> indexURI2Label) throws IOException { Map<String, String> namespace2prefix = new HashMap<String, String>(); JSONArray jsonResults = new JSONArray(); Set<URI> infoConcepts = new HashSet(); StringWriter json = new StringWriter(); for (ObirsResult result : results) { JSONObject jsonResult = new JSONObject(); URI itemResultURI = result.getItemURI(); ItemMetadata metadata = indexer.getMetadata(itemResultURI); jsonResult.put("itemTitle", metadata.title); jsonResult.put("href", metadata.href); jsonResult.put("itemId", metadata.idLiteral); jsonResult.put("itemURI", buildShortURI(result.getItemURI(), namespace2prefix)); jsonResult.put("score", result.getScore()); JSONArray jsonConcepts = new JSONArray(); if (result.getConcepts() != null) { for (ConceptMatch concept : result.getConcepts()) { JSONObject jsonConcept = new JSONObject(); jsonConcept.put("queryConceptURI", buildShortURI(concept.getQueryConceptURI(), namespace2prefix)); jsonConcept.put("matchingConceptURI", buildShortURI(concept.getMatchingConceptURI(), namespace2prefix)); infoConcepts.add(concept.getQueryConceptURI()); infoConcepts.add(concept.getMatchingConceptURI()); jsonConcept.put("relationType", buildShortURI(concept.getRelationType(), namespace2prefix)); jsonConcept.put("score", concept.getScore()); jsonConcepts.add(jsonConcept); }//from ww w.j a va2s.c om } jsonResult.put("concepts", jsonConcepts); jsonResults.add(jsonResult); } JSONArray jsonInfoConcepts = new JSONArray(); for (URI uri : infoConcepts) { JSONObject jsonQueryConcept = new JSONObject(); jsonQueryConcept.put("uri", buildShortURI(uri, namespace2prefix)); jsonQueryConcept.put("label", indexURI2Label.get(uri)); jsonInfoConcepts.add(jsonQueryConcept); } JSONArray jsonInfoNamespace = new JSONArray(); for (Map.Entry<String, String> e : namespace2prefix.entrySet()) { JSONObject jsonQueryConcept = new JSONObject(); jsonQueryConcept.put("ns", e.getKey()); jsonQueryConcept.put("prefix", e.getValue()); jsonInfoNamespace.add(jsonQueryConcept); } JSONObject finalJSONresult = new JSONObject(); finalJSONresult.put("prefixes", jsonInfoNamespace); finalJSONresult.put("results", jsonResults); finalJSONresult.put("infoConcepts", jsonInfoConcepts); finalJSONresult.writeJSONString(json); return json.toString(); }
From source file:es.alrocar.jpe.writer.handler.MiniJPEWriterHandler.java
/** * {@inheritDoc}//from www . j a v a 2 s.c o m */ public Object startPoint() { Map geometry = new LinkedHashMap(); JSONArray coords = new JSONArray(); coords.add(0); coords.add(0); geometry.put("type", "Point"); geometry.put("coordinates", coords); return geometry; }
From source file:me.timothy.ddd.entities.EntityManager.java
public void saveEntities(FileWriter fw) throws IOException { JSONArray jArr = new JSONArray(); JSONObject jObj;/*w w w. j a v a2 s . c om*/ for (Entity e : entities) { EntityInfo ei = e.getEntityInfo(); jObj = new JSONObject(); ei.saveTo(jObj); jArr.add(jObj); } DDDUtils.writeJSONPretty(fw, jArr); }
From source file:org.kitodo.data.index.elasticsearch.type.UserGroupType.java
@SuppressWarnings("unchecked") @Override//w w w . j a v a 2 s.c o m public HttpEntity createDocument(UserGroup userGroup) { LinkedHashMap<String, String> orderedUserGroupMap = new LinkedHashMap<>(); orderedUserGroupMap.put("title", userGroup.getTitle()); orderedUserGroupMap.put("permission", userGroup.getPermission().toString()); JSONArray users = new JSONArray(); List<User> userGroupUsers = userGroup.getUsers(); for (User user : userGroupUsers) { JSONObject userObject = new JSONObject(); userObject.put("id", user.getId().toString()); users.add(userObject); } JSONObject userGroupObject = new JSONObject(orderedUserGroupMap); userGroupObject.put("users", users); return new NStringEntity(userGroupObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:com.bigml.histogram.GroupTarget.java
@Override @SuppressWarnings("unchecked") protected void addJSON(JSONArray binJSON, DecimalFormat format) { JSONArray targetsJSON = new JSONArray(); for (Target target : _target) { target.addJSON(targetsJSON, format); }/*w w w .jav a 2 s. c o m*/ binJSON.add(targetsJSON); }
From source file:com.piusvelte.hydra.HydraRequest.java
private JSONArray packArray(String[] arr) { JSONArray jsonArr = new JSONArray(); for (String s : arr) jsonArr.add(s); return jsonArr; }
From source file:control.AutenticacionServlets.SeleccionarPermisos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww . jav a 2 s .com*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONArray resp = new JSONArray(); JSONArray resp1 = new JSONArray(); try { String rol = request.getParameter("rol"); PermisosAcceso manager = new PermisosAcceso(); resp = manager.SeleccionarPermisos(rol); resp1.add(resp); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObject : resp1) { response.getWriter().write(jsonObject.toString()); } } catch (SQLException ex) { JSONObject jsonObject = new JSONObject(); jsonObject.put("error", 0); } }
From source file:hoot.services.controllers.ingest.RasterToTilesResourceTest.java
@Test @Category(UnitTest.class) public void TestIngestOSMResource() throws Exception { String processScriptName = RASTER_TO_TILES; Assert.assertNotNull(processScriptName); Assert.assertTrue(!processScriptName.isEmpty()); RasterToTilesService rts = new RasterToTilesService(); JSONObject oExpected = new JSONObject(); oExpected.put("caller", "RasterToTilesService"); oExpected.put("exec", processScriptName); JSONArray params = new JSONArray(); JSONObject param = new JSONObject(); param.put("RASTER_OUTPUT_DIR", tileServerPath); params.add(param); param = new JSONObject(); param.put("INPUT", "test"); params.add(param);/* w w w .j a va 2 s . c om*/ param = new JSONObject(); param.put("ZOOM_LIST", "0-1 2-3"); params.add(param); param = new JSONObject(); param.put("RASTER_SIZE", "500"); params.add(param); param = new JSONObject(); param.put("MAP_ID", "1"); params.add(param); oExpected.put("params", params); oExpected.put("exectype", "make"); oExpected.put("erroraswarning", "true"); Method createCommandMethod = RasterToTilesService.class.getDeclaredMethod("createCommand", String.class, String.class, int.class, long.class); createCommandMethod.setAccessible(true); String actual = (String) createCommandMethod.invoke(rts, "test", "0-1 2-3", 500, 1); JSONParser parser = new JSONParser(); JSONObject actualObj = (JSONObject) parser.parse(actual); Assert.assertEquals(oExpected, actualObj); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.json.MapperStatusQuery.java
@SuppressWarnings("unchecked") public String execute(IServletConfig config, String[] parameters) { if (mapper == null) { return ""; }//from w ww . j a v a 2 s . com Map<String, IRegistrationData> registrationData = mapper.getRegistrationData(); // Map<String, IStatusProxy> statusProxyMap = mapper.getStatusProxyMap(); // List<IVirtualVehicleInfo> virtualVehicleList = mapper.getVirtualVehicleList(); JSONArray a = new JSONArray(); for (Entry<String, IRegistrationData> rdEntry : registrationData.entrySet()) { IRegistrationData rd = rdEntry.getValue(); JSONObject o = new JSONObject(); o.put("regDat", rd); a.add(o); } return JSONValue.toJSONString(a); }