List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.StatusProxy.java
@SuppressWarnings("unchecked") @Override// ww w.ja v a 2s . com public void changeSetCourse(List<IRVCommand> courseCommandList, boolean immediate) { JSONArray a = new JSONArray(); for (IRVCommand cmd : courseCommandList) { a.add(rvCommandToJSON(cmd)); } JSONObject o = new JSONObject(); o.put("immediate", Boolean.valueOf(immediate)); o.put("course", a); String x = JSONValue.toJSONString(a); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(setCourseUrl); HttpResponse response; String responseString = ""; try { StringEntity entity = new StringEntity(x, "setcourse/json", null); httppost.setEntity(entity); response = httpclient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) responseString = EntityUtils.toString(response.getEntity()); else LOG.error("Error at accessing " + setCourseUrl + " code=" + statusCode + " reason=" + response.getStatusLine().getReasonPhrase()); LOG.info("Upload new course to " + setCourseUrl + " response=" + responseString); } catch (Exception e) { LOG.error("Can not access " + setCourseUrl, e); } // TODO return a value ? }
From source file:com.conwet.silbops.model.Advertise.java
@Override @SuppressWarnings("unchecked") public JSONArray toJSON() { JSONArray json = new JSONArray(); for (Attribute attribute : attributes) { json.add(attribute.toJSON()); }/*from ww w.j a v a2 s . co m*/ return json; }
From source file:com.google.android.gcm.demo.server.Datastore.java
/** * Gets the number of total devices.// w w w.java 2 s. co m */ public static JSONArray getAllAlertsFromDataStore(int offset, int limit) { JSONArray alerts = null; Transaction txn = datastore.beginTransaction(); try { alerts = new JSONArray(); Query query = new Query(ALERTS).addSort(ALERT_TIME, SortDirection.DESCENDING); Iterable<Entity> entities = datastore.prepare(query) .asIterable(FetchOptions.Builder.withOffset(offset).limit(limit)); for (Entity entity : entities) { JSONObject alert = new JSONObject(); alert.put(ALERT_FROM, (String) entity.getProperty(ALERT_FROM)); alert.put(ALERT_MESSAGE, (String) entity.getProperty(ALERT_MESSAGE)); Date date = (Date) entity.getProperty(ALERT_TIME); SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy"); sd.setTimeZone(TimeZone.getTimeZone("IST")); alert.put(ALERT_TIME, sd.format(date)); alerts.add(alert); } txn.commit(); } finally { if (txn.isActive()) { txn.rollback(); } } return alerts; }
From source file:de.tobiyas.racesandclasses.chat.channels.container.ChannelSaveContainer.java
@SuppressWarnings("unchecked") public void saveParticipants(List<String> participants) { JSONArray tempObject = new JSONArray(); for (String playerName : participants) { tempObject.add(playerName); }//w ww . j av a 2s .c o m this.participants = tempObject.toJSONString(); }
From source file:com.erbjuder.logger.server.entity.impl.Node.java
public JSONObject toJSON() { JSONArray edgeInList = new JSONArray(); for (Edge edge : this.getIncomingEdges()) { edgeInList.add(edge.toJSON()); }// ww w. j a v a2s.c om JSONArray edgeOutList = new JSONArray(); for (Edge edge : this.getOutgoingEdges()) { edgeOutList.add(edge.toJSON()); } JSONArray logMessagesList = new JSONArray(); // for (LogMessage logMessage : this.getLogMessages()) { // logMessagesList.add(logMessage.toJSON()); // } JSONObject node = new JSONObject(); node.put("id", this.getId()); node.put("name", this.getName()); node.put("description", this.getDescription()); node.put("isRoot", this.isRootNode()); node.put("isPartOfGraph", this.isPartOfGraph()); // node.put("graphId", this.getGraph() == null ? "null" : this.getGraph().getId()); node.put("incomingEdges", edgeInList); node.put("outgoingEdges", edgeOutList); node.put("logMessages", logMessagesList); return node; }
From source file:com.imagelake.android.search.Servlet_Components.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from w w w . j a v a2 s . co m jja = new JSONArray(); JSONArray kja = kwdi.getJSONAllKeyWords(); jja.add(kja); List<Categories> categories = cdi.listAllCategories(); JSONArray cja = new JSONArray(); for (Categories c : categories) { JSONObject jo = new JSONObject(); jo.put("id", c.getCategory_id()); jo.put("cat", c.getCategory()); cja.add(jo); } jja.add(cja); JSONArray sja = new JSONArray(); List<User> li = new UserDAOImp().listAllSellers(); if (!li.isEmpty()) { for (User u : li) { JSONObject jo = new JSONObject(); jo.put("id", u.getUser_id()); jo.put("nm", u.getUser_name()); sja.add(jo); } } jja.add(sja); JSONArray ja = new JSONArray(); List<Credits> clist = new CreditsDAOImp().getCreditList(); for (Credits c : clist) { JSONObject jo = new JSONObject(); jo.put("width", c.getWidth()); jo.put("height", c.getHeight()); ja.add(jo); } jja.add(ja); System.out.println(jja.toJSONString()); out.write("json=" + jja.toJSONString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:gr.aueb.mipmapgui.controller.file.ActionInitialize.java
private void getSavedSchemata() { JSONArray schemaFileArr = new JSONArray(); File schemaDir = new File(Costanti.SERVER_MAIN_FOLDER + Costanti.SERVER_SCHEMATA_FOLDER); String[] schemaFiles = schemaDir.list(); for (String file : schemaFiles) { file = file.substring(0, file.lastIndexOf('.')); schemaFileArr.add(file); }//from w w w.ja va 2 s . c o m JSONObject.put("savedSchemata", schemaFileArr); }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.MQLQueryWrapper.java
@SuppressWarnings("unchecked") public MQLQueryWrapper(String namespace, String value) { this.value = value; JSONObject obj = new JSONObject(); JSONArray key = new JSONArray(); JSONArray type = new JSONArray(); obj.put("mid", null); obj.put("type", type); JSONObject contents = new JSONObject(); contents.put("namespace", namespace); contents.put("value", QueryMQL.encodeMQL(value)); key.add(contents); obj.put("key", key); this.MQLquery = StringEscapeUtils.unescapeJavaScript(obj.toJSONString()); }
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: POST /taskmanager/postinstalltasks Add a task to the list of * tasks This is done because of BUG: a call to viewContext.putInstanceData * inside the servlet returns ERROR 500 after a while. * //from w w w . jav a 2s . com * @param headers * http headers * @param ui * uri info * * @return the response */ @POST @Path("/postinstalltasks") @Produces({ "text/html" }) public Response addPostInstallTasks(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String current = viewContext.getInstanceData("post-install-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.add(body); viewContext.putInstanceData("post-install-tasks", array.toString()); String output = "Added task:" + body; return Response.ok(output).type("text/html").build(); }
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: POST /taskmanager/postupdatetasks Add a task to the list of * tasks This is done because of BUG: a call to viewContext.putInstanceData * inside the servlet returns ERROR 500 after a while. * // w w w . j a v a 2 s. c o m * @param headers * http headers * @param ui * uri info * * @return the response */ @POST @Path("/postupdatetasks") @Produces({ "text/html" }) public Response addPostUpdateTasks(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String current = viewContext.getInstanceData("post-update-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.add(body); viewContext.putInstanceData("post-update-tasks", array.toString()); String output = "Added task:" + body; return Response.ok(output).type("text/html").build(); }