List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:bizlogic.Sensors.java
public static void list(Connection DBcon) throws IOException, ParseException, SQLException { Statement st = null;/*w w w . j a v a2 s .co m*/ ResultSet rs = null; try { st = DBcon.createStatement(); rs = st.executeQuery("SELECT * FROM USERCONF.SENSORLIST"); } catch (SQLException ex) { Logger lgr = Logger.getLogger(Sensors.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } try { FileWriter sensorsFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/sensors.json"); sensorsFile.write(""); sensorsFile.flush(); JSONParser parser = new JSONParser(); JSONObject Records = new JSONObject(); JSONObject operation_Obj = new JSONObject(); JSONObject operand_Obj = new JSONObject(); JSONObject unit_Obj = new JSONObject(); JSONObject name_Obj = new JSONObject(); JSONObject ip_Obj = new JSONObject(); JSONObject port_Obj = new JSONObject(); int _total = 0; JSONArray sensorList = new JSONArray(); while (rs.next()) { JSONObject sensor_Obj = new JSONObject(); int id = rs.getInt("sensor_id"); String operation = rs.getString("operation"); int operand = rs.getInt("operand"); String unit = rs.getString("unit"); String name = rs.getString("name"); String ip = rs.getString("IP"); int port = rs.getInt("port"); sensor_Obj.put("recid", id); sensor_Obj.put("operation", operation); sensor_Obj.put("operand", operand); sensor_Obj.put("unit", unit); sensor_Obj.put("name", name); sensor_Obj.put("IP", ip); sensor_Obj.put("port", port); sensorList.add(sensor_Obj); _total++; } rs.close(); Records.put("total", _total); Records.put("records", sensorList); sensorsFile.write(Records.toJSONString()); sensorsFile.flush(); sensorsFile.close(); } catch (IOException ex) { Logger.getLogger(Sensors.class.getName()).log(Level.WARNING, null, ex); } }
From source file:fi.hsl.parkandride.itest.JSONObjectBuilder.java
public JSONArray asArray() { final JSONArray jsonArray = new JSONArray(); jsonArray.add(jsonObject); return jsonArray; }
From source file:com.bigml.histogram.SumResult.java
@SuppressWarnings("unchecked") public JSONArray toJSON(DecimalFormat format) { JSONArray jsonArray = new JSONArray(); jsonArray.add(Utils.roundNumber(_count, format)); _targetSum.addJSON(jsonArray, format); return jsonArray; }
From source file:ezbake.data.elastic.ElasticClient.java
@SuppressWarnings("unchecked") private static void addVisibilityFilter(PercolateQuery query, Authorizations authorizations) throws TException { // Set visibility filter final VisibilityFilterConfig filterConfig = new VisibilityFilterConfig(VISIBILITY_FIELD, EnumSet.of(Permission.READ)); FilterBuilder visibilityFilter = getVisibilityFilter(authorizations, filterConfig); JSONObject visibilityJSON = new JSONObject(visibilityFilter.toString()); JSONObject filteredToAdd = new JSONObject(); JSONObject outer = new JSONObject(query.getQueryDocument()); JSONObject gettingOuterQuery = outer.getJSONObject("query"); try {/*w w w. ja v a 2s . c om*/ JSONObject gettingFiltered = gettingOuterQuery.getJSONObject("filtered"); JSONObject gettingFilters = gettingFiltered.getJSONObject("filter"); JSONArray filters = new JSONArray(); filters.add(gettingFilters); filters.add(visibilityJSON); JSONObject andingFilters = new JSONObject(); andingFilters.put("and", filters); filteredToAdd.put("filter", andingFilters); filteredToAdd.put("query", gettingFiltered.getJSONObject("query")); } catch (JSONException e) { filteredToAdd.put("query", gettingOuterQuery); filteredToAdd.put("filter", visibilityJSON); } JSONObject queryToAdd = new JSONObject(); queryToAdd.put("filtered", filteredToAdd); outer.put("query", queryToAdd); query.setQueryDocument(outer.toString()); }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert List<OFStatistics> to JSONArray * @param ofs/* w ww . j av a 2s .c o m*/ * @return JSONArray */ public static JSONArray toTableStat(List<OFStatistics> ofs) { JSONArray jsonArray = new JSONArray(); for (OFStatistics ofst : ofs) { OFTableStatistics st = (OFTableStatistics) ofst; // st.getPortNumber() st.getReceiveBytes(); FlowscaleController.logger.debug("Maximum Entries {} and and Table id {}", st.getMaximumEntries(), st.getTableId()); FlowscaleController.logger.debug("Name {} and and Table length {}", st.getName(), st.getLength()); JSONObject jsonObject = new JSONObject(); jsonObject.put("match_count", st.getMatchedCount()); jsonObject.put("maximum_entries", st.getMaximumEntries()); jsonObject.put("name", st.getName()); jsonObject.put("table_id", st.getTableId()); jsonObject.put("active_count", st.getActiveCount()); jsonArray.add(jsonObject); } return jsonArray; }
From source file:JSON.WriteQuestionnaireJSON.java
public void buildJSON(String quesString, String quesid) { JSONObject ques = new JSONObject(); ques.put("name", quesid); ques.put("question", quesString); JSONArray options = new JSONArray(); options.add("High"); options.add("Medium"); options.add("Low"); ques.put("options", options); questions.add(ques);// w ww. j av a2 s. c om }
From source file:hoot.services.controllers.job.JobResource.java
private static void setJobInfo(JSONObject jobInfo, JSONObject child, JSONArray children, String stat, String detail) {//w w w . jav a 2 s .c o m for (Object aChildren : children) { JSONObject c = (JSONObject) aChildren; if (c.get("id").toString().equals(child.get("id").toString())) { c.put("status", stat); c.put("detail", detail); return; } } child.put("status", stat); child.put("detail", detail); children.add(child); jobInfo.put("children", children); }
From source file:com.facebook.tsdb.tsdash.server.model.DataPoint.java
@SuppressWarnings("unchecked") public JSONArray toJSONObject() { JSONArray obj = new JSONArray(); obj.add(ts); obj.add(value);//from ww w . j av a 2s . c o m return obj; }
From source file:co.mcme.animations.animations.commands.AnimationFactory.java
public static boolean saveAnimationData(Player p) { //Perform Animation integrity checks if (animationName.trim().isEmpty()) { p.sendMessage(ChatColor.RED/*from w w w . ja va 2 s .c om*/ + "Animation name has not been set. Use /anim name while in Animation setup mode to set up the animation name"); return false; } if ((null == animationDescription) || (animationDescription.trim().isEmpty())) { p.sendMessage(ChatColor.RED + "The animation needs a description. Use /anim description while in Animation setup mode to set up the animation description"); return false; } if (null == origin) { p.sendMessage(ChatColor.RED + "Origin has not been set. Use /anim origin while in Animation setup mode to set up the animation origin"); return false; } if (null == type) { p.sendMessage(ChatColor.RED + "Animation type has not been set. Use /anim type while in Animation setup mode to set up the animation type"); return false; } if (frames.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Frame!"); return false; } if (clips.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Clipboard!"); return false; } if (triggers.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Trigger!"); return false; } //Save all the schematics File animationFolder = new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder() + File.separator + "schematics" + File.separator + "animations" + File.separator + animationName); if (animationFolder.exists()) { try { delete(animationFolder); } catch (IOException ex) { Logger.getLogger(AnimationFactory.class.getName()).log(Level.SEVERE, null, ex); } } animationFolder.mkdirs(); for (MCMEClipboardStore cs : clips) { if (cs.getUses() > 0) { saveClipboardToFile(cs.getClip(), cs.getSchematicName(), animationFolder); } } //Save the configuration file JSONObject configuration = new JSONObject(); configuration.put("name", animationName); configuration.put("world-index", p.getWorld().getName()); JSONArray frameList = new JSONArray(); JSONArray durationList = new JSONArray(); for (int i = 0; i < frames.size(); i++) { frameList.add(frames.get(i).getSchematic().getSchematicName()); durationList.add(frames.get(i).getDuration()); } configuration.put("frames", frameList); configuration.put("durations", durationList); JSONArray originPoints = new JSONArray(); originPoints.add((int) Math.floor(origin.getX())); originPoints.add((int) Math.floor(origin.getY())); originPoints.add((int) Math.floor(origin.getZ())); configuration.put("origin", originPoints); configuration.put("type", type.toString()); JSONArray interactions = new JSONArray(); for (AnimationTrigger at : triggers) { interactions.add(at.toJSON()); } configuration.put("interactions", interactions); JSONArray animationActions = new JSONArray(); for (AnimationAction a : actions) { animationActions.add(a.toJSON()); } if (animationActions.size() > 0) { configuration.put("actions", animationActions); } configuration.put("creator", owner.getDisplayName()); configuration.put("description", animationDescription); try { FileWriter fw = new FileWriter(new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder() + File.separator + "schematics" + File.separator + "animations" + File.separator + animationName + File.separator + "conf.json")); fw.write(configuration.toJSONString()); fw.flush(); fw.close(); } catch (IOException ex) { p.sendMessage("Error saving Animation configuration file!"); return false; } p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Animation " + animationName + " saved and ready to run! Use /anim reset to reload the configuration."); return true; }
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)); }