List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:naftoreiclag.villagefive.util.json.JSONUtil.java
public static <SomeJSONThingy extends JSONThingy> JSONArray encodeList(List<SomeJSONThingy> list) { JSONArray conv = new JSONArray(); for (int i = 0; i < list.size(); ++i) { SomeJSONThingy thing = list.get(i); thing.setJsonIndex(i);/*from www. j a va2s . c o m*/ conv.add(thing); } return conv; }
From source file:app.NotificationJSONizer.java
public static void jsonize(ArrayList<backend.Notification> notis, PrintWriter out) { JSONArray a = new JSONArray(); notis.stream().forEach((noti) -> { JSONObject o = noti.jsonize();//from ww w . ja v a 2s .c o m o.put("type", noti.get_type().toString()); a.add(o); }); out.print(a.toString()); }
From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java
public static String convertTOJSON(List<Metric> metrics) { JSONArray children = new JSONArray(); for (Metric m : metrics) { JSONObject metricJSON = new JSONObject(); metricJSON.put("name", m.getName()); metricJSON.put("unit", m.getMeasurementUnit()); metricJSON.put("type", "" + m.getType()); children.add(metricJSON);/*w ww . ja va2s.c om*/ } return children.toJSONString(); }
From source file:com.mum.edu.cs472.dictServlet.java
public static JSONArray convertToJSON(ResultSet resultSet) throws Exception { JSONArray jsonArray = new JSONArray(); while (resultSet.next()) { int total_rows = resultSet.getMetaData().getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 0; i < total_rows; i++) { obj.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1)); jsonArray.add(obj);//from w w w .j a v a 2 s .co m } } return jsonArray; }
From source file:model.Post_store.java
public static void add_post(String title, String content) { JSONObject obj = new JSONObject(); obj.put("title", title); obj.put("content", content); JSONArray comments = new JSONArray(); obj.put("comments", comments); JSONArray UA_comments = new JSONArray(); obj.put("UA_comments", UA_comments); int lastid = getlastid(); obj.put("id", lastid); try (FileWriter file = new FileWriter(root + "posts/" + lastid + ".json");) { file.write(obj.toJSONString());//from ww w . ja va 2 s. co m file.flush(); file.close(); } catch (IOException e) { System.out.println(e); } lastid++; setlastid(lastid); //System.out.print(obj); }
From source file:naftoreiclag.villagefive.util.json.JSONUtil.java
public static <SomeJSONThingy extends JSONThingy> JSONArray encodePntrList(List<SomeJSONThingy> list) { JSONArray conv = new JSONArray(); for (int i = 0; i < list.size(); ++i) { conv.add(list.get(i).getJsonIndex()); }// ww w . ja va2 s . c o m return conv; }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static String clansToJSON(Collection<Clan> clans) { if (clans == null) { return null; }//from ww w. ja v a2s.c o m JSONArray array = new JSONArray(); for (Clan clan : clans) { array.add(clan.getID()); } return array.toJSONString(); }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert from status of OFPhysicalPort to JSONArray * @param portList//from w w w. ja v a2 s . c o m * @return JSONArray of an ArrayList<OFPhysicalPort> */ public static JSONArray toPortStatus(List<OFPhysicalPort> portList) { JSONArray jsonArray = new JSONArray(); for (OFPhysicalPort pp : portList) { JSONObject obj = new JSONObject(); if (pp.getPortNumber() < 0) { continue; } obj.put("port_id", pp.getPortNumber()); obj.put("port_address", HexString.toHexString(pp.getHardwareAddress())); obj.put("config", pp.getConfig()); obj.put("supported", pp.getSupportedFeatures()); obj.put("current", pp.getCurrentFeatures()); obj.put("state", pp.getState()); FlowscaleController.logger.debug("port {}", pp.getPortNumber()); FlowscaleController.logger.debug("h/w {}", HexString.toHexString(pp.getHardwareAddress())); FlowscaleController.logger.debug("state {}", pp.getState()); FlowscaleController.logger.debug("-------"); jsonArray.add(obj); } return jsonArray; }
From source file:com.p000ison.dev.copybooks.util.Helper.java
public static String fromListToJSONString(String key, List<String> list) { JSONObject json = new JSONObject(); JSONArray array = new JSONArray(); array.addAll(list);/*from ww w . ja v a 2 s . c o m*/ json.put(key, array); return json.toString(); }
From source file:com.healthcit.analytics.utils.ExcelExportUtils.java
@SuppressWarnings("unchecked") public static void streamVisualizationDataAsExcelFormat(OutputStream out, JSONObject data) { // Get the array of columns JSONArray jsonColumnArray = (JSONArray) data.get(COLUMNS_JSON_KEY); String[] excelColumnArray = new String[jsonColumnArray.size()]; for (int index = 0; index < excelColumnArray.length; ++index) { excelColumnArray[index] = (String) ((JSONObject) jsonColumnArray.get(index)).get(LABEL_JSON_KEY); }/*w w w. j av a 2 s. com*/ // Get the array of rows JSONArray jsonRowArray = (JSONArray) data.get(ROWS_JSON_KEY); JSONArray excelRowArray = new JSONArray(); Iterator<JSONObject> jsonRowIterator = jsonRowArray.iterator(); while (jsonRowIterator.hasNext()) { JSONArray rowCell = (JSONArray) jsonRowIterator.next().get(ROWCELL_JSON_KEY); JSONObject excelRowObj = new JSONObject(); for (int index = 0; index < rowCell.size(); ++index) { excelRowObj.put(excelColumnArray[index], ((JSONObject) rowCell.get(index)).get(ROWCELLVALUE_JSON_KEY)); } excelRowArray.add(excelRowObj); } // build the Excel outputstream Json2Excel.build(out, excelRowArray.toJSONString(), excelColumnArray); }