List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:jsonconverter.createandwrite.JSONObjectCreator.java
public JSONObject objectArranger() { JSONArray array = new JSONArray(); for (JSONSearchObjectCreator searchObject : arraySearchObjs) { JSONObject tempObj = new JSONObject(); tempObj.put("id", searchObject.getId()); tempObj.put("path", searchObject.getPath()); tempObj.put("title", searchObject.getTitle()); tempObj.put("frag", searchObject.getFragment()); array.add(tempObj); }/* w w w . j a v a 2 s . co m*/ obj.put("Search", array); return obj; }
From source file:cpd4414.assign2.OrderQueueTest.java
@Test public void testGeneratereportByOrder() throws OrderQueue.IfNoCustomer, OrderQueue.IfNoPurchase, OrderQueue.EmptyTimeReceived, OrderQueue.EmptyTimeprocessed, ParseException { OrderQueue orderqueue = new OrderQueue(); Order order = new Order("Cust1", "Name1"); order.addPurchase(new Purchase(1, 8)); orderqueue.add(order);//from w ww . j a va 2 s . c om Order order_new = new Order("Cust2", "Name2"); order_new.addPurchase(new Purchase(2, 4)); orderqueue.add(order_new); Order ordernext = orderqueue.nextOrder(); orderqueue.process(ordernext); orderqueue.methodfulfill(ordernext); JSONObject expresult = new JSONObject(); JSONArray orders = new JSONArray(); JSONObject o1 = new JSONObject(); o1.put("customerId", "Cust1"); o1.put("customerName", "Name1"); o1.put("timeReceived", new Date().toString()); o1.put("timeProcessed", new Date().toString()); o1.put("timeFulfilled", new Date().toString()); JSONArray pList = new JSONArray(); JSONObject p1 = new JSONObject(); p1.put("ProductId", 1); p1.put("quantity", 8); pList.add(p1); o1.put("purchases", pList); o1.put("notes", null); orders.add(o1); JSONObject o2 = new JSONObject(); o2.put("customerId", "Cust2"); o2.put("customerName", "Name2"); o2.put("timeReceived", new Date().toString()); o2.put("timeProcessed", null); o2.put("timeFulfilled", null); JSONArray pList1 = new JSONArray(); JSONObject p2 = new JSONObject(); p2.put("ProductId", 2); p2.put("quantity", 4); pList1.add(p2); o2.put("purchases", pList1); o2.put("notes", null); orders.add(o2); expresult.put("orders", orders); String resultString = orderqueue.generateReport(); // JSONObject newsetof = (JSONObject) JSONValue.parseWithException(expresult.toJSONString()); JSONObject result = (JSONObject) JSONValue.parseWithException(resultString); System.out.println(result); assertEquals(expresult.toJSONString(), result.toJSONString()); }
From source file:hoot.services.controllers.ingest.RasterToTilesService.java
protected JSONObject _createCommandObj(String name, String zoomList, int rasterSize) throws Exception { String argStr = null;/* w w w .j a v a 2 s.c o m*/ JSONArray commandArgs = new JSONArray(); JSONObject arg = new JSONObject(); arg.put("RASTER_OUTPUT_DIR", _tileServerPath); commandArgs.add(arg); arg = new JSONObject(); arg.put("INPUT", name); commandArgs.add(arg); arg = new JSONObject(); arg.put("ZOOM_LIST", zoomList); commandArgs.add(arg); arg = new JSONObject(); arg.put("RASTER_SIZE", "" + rasterSize); commandArgs.add(arg); JSONObject jsonArgs = _createPostBody(commandArgs); jsonArgs.put("throwerror", "false"); return jsonArgs; }
From source file:de.fhg.fokus.odp.portal.datasets.searchresults.BrowseDataSetsSearchResults.java
/** * This method reverses a JSONArray.// w w w . j av a 2 s. c o m * * @param comments * the JSONArray to be reversed * @return the reversed JSONArray */ private JSONArray reverseJSONArray(JSONArray comments) { JSONArray toReturn = new JSONArray(); for (int i = comments.size() - 1; i >= 0; i--) { toReturn.add(comments.get(i)); } return toReturn; }
From source file:net.bashtech.geobot.JSONUtil.java
public static ArrayList<String> tmiChatters(String channel) { try {/*www. ja v a 2 s . c o m*/ JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContent("https://tmi.twitch.tv/group/user/" + channel + "/chatters")); JSONObject jsonObject = (JSONObject) obj; JSONObject chatters = (JSONObject) jsonObject.get("chatters"); JSONArray viewers = (JSONArray) chatters.get("viewers"); JSONArray moderators = (JSONArray) chatters.get("moderators"); for (int i = 0; i < moderators.size(); i++) { viewers.add(moderators.get(i)); } return viewers; } catch (Exception ex) { System.out.println("Failed to get chatters"); return null; } }
From source file:cz.zeno.miner.stratum.StratumClient.java
private void authorize(String workername, String password) throws IOException { //create JSON request JSONObject obj = new JSONObject(); obj.put("id", new Integer(2)); obj.put("method", "mining.authorize"); JSONArray params = new JSONArray(); params.add(workername); params.add(password);/* ww w .java2 s .c o m*/ obj.put("params", params); //append to network stream new OutputStreamWriter(outputStream).append(obj.toJSONString() + Constants.NEWLINE).flush(); }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Test public void itemAsArrayWorks() throws Exception { JSONArray data = new JSONArray(); data.add("audit"); pub.put("dataClass", data); jsonCfg.put("publisher", pub); Config cfg = new Config("/path/to/nothing"); JSONArray data2 = cfg.itemAsArray("dataClass", pub, true); assertEquals(data, data2);// w w w . ja va 2 s .c o m }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Test(expected = ConfigurationException.class) public void updateKnownHostsFailsWhenHostIsNotAString() throws Exception { JSONObject peer1 = new JSONObject(); JSONArray hosts = new JSONArray(); hosts.add(jsonCfg); peer1.put("hosts", hosts); Config cfg = new Config("/path/to/nothing"); cfg.updateKnownHosts(peer1);/*from w ww .ja va2 s.c om*/ }
From source file:gwap.rest.PastTerminaSessionBean.java
private JSONArray getTopicOfTerm() { Query q = customSourceBean.query("topic.byResource"); q.setParameter("resource", this.term); List<Topic> tops = q.getResultList(); JSONArray arr = new JSONArray(); for (Topic t : tops) { arr.add(t.getName()); }//from ww w .ja v a 2s . com return arr; }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Test public void recordSetFromArrayWorks() throws Exception { JSONArray types = new JSONArray(); types.add("journal"); types.add("audit"); types.add("log"); Config cfg = new Config("/path/to/nothing"); Set<RecordType> typeSet = cfg.recordSetFromArray(types); assertNotNull(typeSet);/*from w ww . j av a2s . c o m*/ assertFalse(typeSet.isEmpty()); assertTrue(typeSet.contains(RecordType.Journal)); assertTrue(typeSet.contains(RecordType.Audit)); assertTrue(typeSet.contains(RecordType.Log)); }