List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:com.bigml.histogram.MapCategoricalTarget.java
@Override @SuppressWarnings("unchecked") protected void addJSON(JSONArray binJSON, DecimalFormat format) { JSONObject counts = new JSONObject(); for (Entry<Object, Double> categoryCount : _counts.entrySet()) { Object category = categoryCount.getKey(); double count = categoryCount.getValue(); counts.put(category, Utils.roundNumber(count, format)); }/*from w ww . j av a 2 s. c o m*/ binJSON.add(counts); }
From source file:com.imagelake.android.category.Servlet_categories.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); CategoriesDAOImp categoryDAOImp = new CategoriesDAOImp(); JSONArray ja = new JSONArray(); ArrayList<Categories> categoriesList = (ArrayList<Categories>) categoryDAOImp.listAllCategories(); if (!categoriesList.isEmpty()) { for (Categories cc : categoriesList) { JSONObject jo = new JSONObject(); jo.put("id", cc.getCategory_id()); jo.put("cat", cc.getCategory()); ja.add(jo); }//from w w w. jav a2 s . c om out.write("json=" + ja.toJSONString()); } else { JSONObject jo = new JSONObject(); jo.put("id", 0); jo.put("cat", "No category found."); ja.add(jo); out.write("json=" + ja.toJSONString()); } }
From source file:is.brendan.WarpMarkers.WarpMarkersWarpInfo.java
public JSONArray load() { JSONArray jsonList = new JSONArray(); final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames()); final Iterator<String> iterator = warpNameList.iterator(); while (iterator.hasNext()) { String warpName = iterator.next(); jsonList.add(getWarp(warpName)); }//from w ww .j ava2s . co m return jsonList; }
From source file:es.alrocar.jpe.writer.GeoJSONWriter.java
public String write(ArrayList<JTSFeature> features) throws JSONException, BaseException { String result = null;//from w w w . j av a 2s . c o m JSONObject featureCollection = new JSONObject(); featureCollection.put("type", "featureCollection"); JSONArray featuresJSON = new JSONArray(); JSONObject featureJSON; JSONObject point; JSONObject properties; JSONArray coords; for (JTSFeature feature : features) { featureJSON = new JSONObject(); point = new JSONObject(); properties = new JSONObject(); coords = new JSONArray(); featureJSON.put("type", "Feature"); point.put("type", "Point"); coords.add(feature.getGeometry().getGeometry().getCoordinate().x); coords.add(feature.getGeometry().getGeometry().getCoordinate().y); point.put("coordinates", coords); Set keys = feature.getAttributes().keySet(); Iterator it = keys.iterator(); String key; while (it.hasNext()) { key = it.next().toString(); properties.put(key, feature.getAttribute(key).value); } featureJSON.put("geometry", point); featureJSON.put("properties", properties); featuresJSON.add(featureJSON); } featureCollection.put("features", featuresJSON); result = featureCollection.toString(); return result; }
From source file:cc.pinel.mangue.storage.StateStorage.java
public void setChapter(String mangaId, String chapterNumber) throws IOException { JSONObject json = null;/*from w ww .j av a 2s. co m*/ try { json = readJSON(); } catch (Exception e) { // ignored } if (json == null) json = new JSONObject(); JSONArray jsonMangas = (JSONArray) json.get("mangas"); if (jsonMangas == null) { jsonMangas = new JSONArray(); json.put("mangas", jsonMangas); } JSONObject jsonManga = findManga(jsonMangas, mangaId); if (jsonManga == null) { jsonManga = new JSONObject(); jsonManga.put("id", mangaId); jsonMangas.add(jsonManga); } jsonManga.put("chapterNumber", chapterNumber); writeJSON(json); }
From source file:modelo.ParametrizacionManagers.MotivosVisitas.java
/** * * Llama al delegate para Eliminar un Laboratorio * * @param codigo // www.ja v a 2 s . c o m * @throws Exception */ public JSONArray Eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarMotivosVisitas delete = new EliminarMotivosVisitas(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:modelo.ParametrizacionManagers.TiposContactos.java
/** * * Llama al delegate para Eliminar una tipo de contacto * @param codigo /*from ww w .ja va 2s .c o m*/ * @throws Exception */ public JSONArray eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarTiposContactos delete = new EliminarTiposContactos(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:is.brendan.WarpMarkers.WarpMarkersWarpInfo.java
public JSONArray getUpdates(int updatesLife) { JSONArray jsonList = new JSONArray(); final Iterator<HashMap> iterator = updates.iterator(); while (iterator.hasNext()) { HashMap update = iterator.next(); if (System.currentTimeMillis() - (Long) update.get("timestamp") < updatesLife) { jsonList.add(getUpdate(update)); }// w ww .ja v a 2s.c o m } return jsonList; }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLMongoDB.java
private int storeDataEvents(DataList events) { Date t1 = new Date(); DataItem item;/* w ww. java 2s . c om*/ EventItem event; ValueItem value; ArrayList<WriteModel<Document>> list = new ArrayList<>(); try { for (int i = 0; i <= events.getHighWaterMark() && (item = events.getItem(i)) != null; i++) { if (!(item instanceof EventItem)) continue; event = (EventItem) item; //JDebug.out.info(getTagOfDp(event.getDp())); Document obj = new Document("type", "event").append("tag", getTagOfDp(event.getDp())) .append("ns", event.getTimeNS()) // ISODate does not support nanoseconds .append("ts", new Date(event.getTimeMS())) // ISODate ; // .append("sys", event.getDp().getSystem()) // .append("dp", event.getDp().getDp()) // .append("el", event.getDp().getElement()) // .append("dpel", event.getDp().getDpEl()); // value value = event.getValue(); Map<String, Object> map = new HashMap<>(); // value_number Double dval = value.getDouble(); if (dval != null) map.put("number", dval); // value_string if (value.getString() != null) map.put("text", value.getString()); // value_timestamp if (value.getTime() != null) map.put("time", value.getTime()); // dynvar if (value.getVariableType() == VariableType.DynVar) { if (value.getValueObject() instanceof DynVar) { DynVar dyn = (DynVar) value.getValueObject(); JSONArray arr = new JSONArray(); dyn.asList().forEach((row) -> arr.add(row.getValueObject())); map.put("array", arr); } } obj.append("value", map); // attributes if (event.hasAttributes()) { obj.append("status", event.getStatus()); obj.append("manager", event.getManager()); obj.append("user", event.getUser()); } // check if text is a json document if (documents && value.getString() != null) { try { Object doc = (new JSONParser()).parse(value.getString()); obj.append("document", doc); } catch (ParseException ex) { // no json text } } list.add(new InsertOneModel<>(obj)); //JDebug.out.info(obj.string()); } evcoll.bulkWrite(list, new BulkWriteOptions().ordered(false)); Date t2 = new Date(); addServerStats(events.getHighWaterMark(), t2.getTime() - t1.getTime()); return INoSQLInterface.OK; } catch (MongoBulkWriteException ex) { // TODO mongodb bulk exception //JDebug.out.log(Level.SEVERE, "Bulk exception {0} on {1} records.", new Object[]{ex.getCode(), ex.getWriteErrors().size()}); //JDebug.StackTrace(Level.SEVERE, ex); return INoSQLInterface.ERR_UNRECOVERABLE; } catch (Exception ex) { JDebug.StackTrace(Level.SEVERE, ex); return INoSQLInterface.ERR_REPEATABLE; } }
From source file:edu.vt.vbi.patric.common.ExpressionDataCollection.java
public void filter(String item, String input) throws FileNotFoundException { JSONArray temp = null;/*from ww w .ja v a 2 s .c o m*/ List items = Arrays.asList(item.split(",")); if (CONTENT_SAMPLE.equals(input)) { temp = sample; } else if (CONTENT_EXPRESSION.equals(input)) { temp = expression; } JSONArray ret = new JSONArray(); assert temp != null; for (Object aTemp : temp) { JSONObject a = (JSONObject) aTemp; if (items.contains(a.get("pid").toString())) { ret.add(a); } } if (CONTENT_SAMPLE.equals(input)) { sample = ret; } else if (CONTENT_EXPRESSION.equals(input)) { expression = ret; } }