List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java
@SuppressWarnings("unchecked") private JSONArray generateRows() { // figure out the entire time series ArrayList<Long> timeSeries = new ArrayList<Long>(); for (Metric metric : metrics) { for (TagsArray t : metric.timeSeries.keySet()) { timeSeries = TimeSeries.merge(timeSeries, metric.timeSeries.get(t)); }/*from ww w . ja v a 2s. c om*/ } JSONObject nullCell = new JSONObject(); JSONArray rows = new JSONArray(); for (long ts : timeSeries) { JSONObject row = new JSONObject(); JSONArray cells = new JSONArray(); cells.add(newTsCell(ts)); for (Metric metric : metrics) { for (TagsArray t : metric.timeSeries.keySet()) { ArrayList<DataPoint> points = metric.timeSeries.get(t); if (points.size() > 0 && points.get(0).ts == ts) { cells.add(newDataCell(points.get(0).value)); points.remove(0); } else { cells.add(nullCell); } } } row.put("c", cells); rows.add(row); } return rows; }
From source file:com.mobicage.rogerthat.form.FloatListWidgetResult.java
@SuppressWarnings("unchecked") @Override//from ww w . j a va 2 s . c o m public JSONObject toJSONObject() { JSONObject obj = new JSONObject(); if (this.values == null) obj.put("values", null); else { JSONArray array = new JSONArray(); for (Double val : this.values) { array.add(val); } obj.put("values", array); } return obj; }
From source file:com.mobicage.rogerthat.form.UnicodeListWidgetResult.java
@SuppressWarnings("unchecked") @Override//w ww . j a v a 2 s . c om public JSONObject toJSONObject() { JSONObject obj = new JSONObject(); if (this.values == null) obj.put("values", null); else { JSONArray array = new JSONArray(); for (String val : this.values) { array.add(val); } obj.put("values", array); } return obj; }
From source file:com.itmanwuiso.checksums.dao.ResultJSONWriter.java
@SuppressWarnings("unchecked") public boolean write(List<HashResult> resuls, OutputStream outputStream) { if (null == resuls || outputStream == null) { throw new InvalidArgumentException("Resuls or OutputStream is " + "null."); }/*from w w w . j a v a2 s . c o m*/ JSONArray jsons = new JSONArray(); for (HashResult hr : resuls) { jsons.add(converter.resultToJson(hr)); } try { outputStream.write(jsons.toString().getBytes()); outputStream.flush(); outputStream.close(); jsons.clear(); return true; } catch (IOException io) { logger.error("", io); } return false; }
From source file:fr.nantes.web.quizz.servlets.Nbmovies.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int countmovies = Sparql.countMovies(); JSONArray result = new JSONArray(); JSONObject map = new JSONObject(); map.put("count", countmovies); result.add(map); response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(result);// www.j a va 2s . c o m } }
From source file:co.mcme.animations.triggers.BlockInteractTrigger.java
@Override public JSONObject toJSON() { JSONObject result = new JSONObject(); JSONObject data = new JSONObject(); JSONArray blocks = new JSONArray(); for (Vector v : triggerLocation) { JSONObject blockData = new JSONObject(); JSONArray vect = new JSONArray(); vect.add((int) v.getX()); vect.add((int) v.getY()); vect.add((int) v.getZ()); blockData.put("block", vect); blocks.add(blockData);/*w ww. j a v a2s .com*/ } data.put("frame", frame); data.put("blocks", blocks); result.put("block_interaction", data); return result; }
From source file:fr.nantes.web.quizz.servlets.Nbdirectors.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int countdirectors = Requetesdatastore.getcountdirectors(); JSONArray result = new JSONArray(); JSONObject map = new JSONObject(); map.put("count", countdirectors); result.add(map); response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(result);// w ww. jav a2 s. com } }
From source file:net.sf.okapi.filters.drupal.Node.java
@SuppressWarnings("unchecked") public void setBody(String lang, String body, String summary) { JSONObject bodyVal = new JSONObject(); bodyVal.put("value", body); if (summary != null) { bodyVal.put("summary", summary); }/*from www.jav a 2s. c o m*/ JSONArray bodyArr = new JSONArray(); bodyArr.add(bodyVal); JSONObject bodyLang = new JSONObject(); bodyLang.put(lang, bodyArr); store.put("body", bodyLang); }
From source file:com.oic.event.map.GetMapUserList.java
@Override public void ActionEvent(JSONObject json, WebSocketListener webSocket) { JSONObject responseJSON = new JSONObject(); responseJSON.put("method", "getmapuserlist"); if (!validation(json)) { responseJSON.put("status", 1); webSocket.sendJson(responseJSON); return;//from ww w .ja va 2 s . c o m } int mapid = Integer.parseInt(json.get("mapid").toString()); MapFactory factory = MapFactory.getInstance(); OicMap map = factory.getMap(mapid); JSONArray charactersJSON = new JSONArray(); try { for (Long userid : map.getUserIdList()) { charactersJSON.add(userid); } } catch (NullPointerException ex) { } responseJSON.put("userlist", charactersJSON); webSocket.sendJson(responseJSON); }
From source file:gov.nih.nci.ispy.web.ajax.ReporterLookup.java
/** * this ajax method looks up reporters using gexpannotation service * based on gene symbol and array platform. An addition parameter is * provided so that the callback(javascript) knows where to put the collection * This last paramter is an id from the ui element. * NOTE: the id passed in WILL be used in the callback...make sure it is there! *//* w w w.j a v a2 s .co m*/ public String lookup(String gene, String arrayPlatform, String uiElement) { Collection<String> reporters = new HashSet<String>(); //set up geneCollection Collection<String> genes = new ArrayList<String>(); genes.add(gene); //set up array platform by finding the appropriate type String[] uiString = arrayPlatform.split("#"); String myClassName = uiString[0]; String myValueName = uiString[1]; Enum myType = EnumHelper.createType(myClassName, myValueName); if (myType instanceof ArrayPlatformType) { GeneExprAnnotationService gs = GeneExprAnnotationServiceFactory.getInstance(); reporters = gs.getReporterNamesForGeneSymbols(genes, (ArrayPlatformType) myType); } /* reporterResultArray variable holds reporter objects like the result * list of reporters (in its own array called reporterList), * the results String, and the UIElement */ JSONArray reporterResultArray = new JSONArray(); JSONObject resultsObject = new JSONObject(); JSONArray reporterList = new JSONArray(); for (String reporter : reporters) { reporterList.add(reporter); } String results = "notFound"; if (!reporterList.isEmpty()) { results = "found"; } resultsObject.put("gene", gene); resultsObject.put("results", results); resultsObject.put("reporters", reporterList); resultsObject.put("elementId", uiElement); reporterResultArray.add(resultsObject); return reporterResultArray.toString(); }