List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:emcali.ami.control.webservice.IPTVAMIWebService.java
private JSONObject getData(JSONObject req, JSONObject resp) { Calendar cal = new GregorianCalendar(); DateFormat dateformat = new SimpleDateFormat("dd-MM-YYYY"); Date today = cal.getTime();/*from ww w.j a va2 s . c o m*/ cal.add(Calendar.DAY_OF_MONTH, -11); Date tendaysago = cal.getTime(); String telcoid = (String) req.get("suscriptor"); TelcoInfoJpaController tijc = new TelcoInfoJpaController(utx, emf); TelcoInfo ti = tijc.findTelcoInfo(Long.parseLong(telcoid)); try { JSONObject data = new JSONObject(); JSONArray consumos = new JSONArray(); AmyMedidores med = ti.getFkAmyMedidores(); ComercialClientes cc = ti.getFkComercialClientes(); List<AmyConsumos> ac = med.getAmyConsumosList(); data.put("id_cliente", cc.getIdClientes()); data.put("nombre_cliente", cc.getNombreClientes()); data.put("direccion", cc.getDireccion()); data.put("serial_medidor", med.getSerial()); for (AmyConsumos amic : ac) { if (amic.getFkAmyInterval().getIntervalo().equals("Dia")) { Date fechacons = amic.getFechaConsumo(); if ((fechacons.compareTo(tendaysago) > 0) && fechacons.before(today)) { JSONObject consumo = new JSONObject(); consumo.put("consumo", amic.getConsumo()); consumo.put("fecha", dateformat.format(amic.getFechaConsumo())); consumos.add(consumo); } } } data.put("consumos", consumos); resp.put("data", data); } catch (NullPointerException ex) { resp.put("message", "Invalid Telco user"); resp.put("type", "error"); } return resp; }
From source file:com.web.mavenproject6.controller.CameraController.java
@ResponseBody @RequestMapping(value = "/camera", method = RequestMethod.POST) public String upload(@RequestParam(value = "imgdata", required = false) String imgdata, HttpServletRequest request)/*from w ww. ja v a 2 s . c o m*/ throws FileNotFoundException, IOException, GeneralSecurityException, JSONException { if (StringUtils.isEmpty(imgdata)) { //return (new Date()).toString(); } JSONObject o = new JSONObject(imgdata); imgdata = new String(Base64.getDecoder().decode(o.getString("qr"))); JSONArray ar = new JSONArray(); JSONObject resultJson = new JSONObject(); JSONObject obj = new JSONObject(); obj.put("propNumber", "0000001"); obj.put("propDate", (new Date()).toString()); obj.put("fname", "?"); obj.put("sname", "");// obj.put("tname", "?");// obj.put("pasport", "898999");// obj.put("level", "10"); obj.put("userId", "10"); ar.add(obj); resultJson.put("user", ar); simpleLog.add(obj); return resultJson.toString(); }
From source file:biomine.bmvis2.pipeline.ManualGroupOperation.java
@Override public JSONObject toJSON() { JSONObject ret = new JSONObject(); JSONArray nodesArr = new JSONArray(); nodesArr.addAll(nodes);//from w w w . j a v a 2 s.c om ret.put("nodes", nodesArr); return ret; }
From source file:com.telefonica.iot.cygnus.utils.NGSIUtilsTest.java
/** * [NGSIUtils.getGeometry] -------- When getting a geometry, a CartoDB point is obtained when passing * an attribute with 'geometry' metadata. *//*from ww w . j a va 2 s .co m*/ @Test public void testGetGeometryMetadata() { System.out.println(getTestTraceHead("[Utils.getLocation]") + "-------- When getting a geometry, a CartoDB point is obtained when passing an attribute " + "with 'location' metadata"); JSONObject metadataJson = new JSONObject(); metadataJson.put("name", "location"); metadataJson.put("type", "string"); metadataJson.put("value", "WGS84"); JSONArray metadatasJson = new JSONArray(); metadatasJson.add(metadataJson); String attrMetadataStr = metadatasJson.toJSONString(); String attrValue = "-3.7167, 40.3833"; String attrType = "coordinates"; // irrelevant for this test boolean swapCoordinates = false; // irrelevant for this test ImmutablePair<String, Boolean> geometry = NGSIUtils.getGeometry(attrValue, attrType, attrMetadataStr, swapCoordinates); try { assertEquals("ST_SetSRID(ST_MakePoint(-3.7167,40.3833), 4326)", geometry.getLeft()); System.out.println(getTestTraceHead("[Utils.getLocation]") + "- OK - Geometry '" + geometry.getLeft() + "' obtained for an attribute with metadata '" + attrMetadataStr + "' and value '" + attrValue + "'"); } catch (AssertionError e) { System.out.println(getTestTraceHead("[Utils.getLocation]") + "- FAIL - Geometry '" + geometry.getLeft() + "' obtained for an attribute with metadata '" + attrMetadataStr + "' and value '" + attrValue + "'"); throw e; } // try catch // try catch }
From source file:jp.aegif.nemaki.rest.GroupResource.java
@SuppressWarnings("unchecked") @GET/*from ww w .java 2s.c om*/ @Path("/list") @Produces(MediaType.APPLICATION_JSON) public String list(@PathParam("repositoryId") String repositoryId) { boolean status = true; JSONObject result = new JSONObject(); JSONArray listJSON = new JSONArray(); JSONArray errMsg = new JSONArray(); List<Group> groupList; try { groupList = principalService.getGroups(repositoryId); for (Group group : groupList) { JSONObject groupJSON = convertGroupToJson(group); listJSON.add(groupJSON); } result.put(ITEM_ALLGROUPS, listJSON); } catch (Exception ex) { ex.printStackTrace(); addErrMsg(errMsg, ITEM_ALLGROUPS, ErrorCode.ERR_LIST); } result = makeResult(status, result, errMsg); return result.toString(); }
From source file:com.des.paperbase.ManageData.java
public void insert(String Tablename, Map<String, Object> value) throws IOException, ParseException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); JSONObject table = new JSONObject(); JSONObject field = new JSONObject(); JSONArray record = new JSONArray(); List<String> keySet = g.getKeyFromMap(value); if (data.equalsIgnoreCase("{\"data\":[]}")) { for (int i = 0; i < keySet.size(); i++) { field.put(keySet.get(i), value.get(keySet.get(i))); }//from www. j a v a2s . c o m record.add(field); table.put("data", record); g.writefile(table.toJSONString(), PATH_FILE + "\\" + Tablename + ".json"); } else { JSONObject json = (JSONObject) new JSONParser().parse(data); JSONArray OldValue = (JSONArray) json.get("data"); for (int i = 0; i < keySet.size(); i++) { field.put(keySet.get(i), value.get(keySet.get(i))); } OldValue.add(field); json.put("data", OldValue); g.writefile(json.toJSONString(), PATH_FILE + "\\" + Tablename + ".json"); } }
From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONBasicRollupsOutputSerializer.java
protected JSONArray transformDataToJSONArray(MetricData metricData, Set<MetricStat> filterStats) throws SerializationException { Points points = metricData.getData(); final JSONArray data = new JSONArray(); final Set<Map.Entry<Long, Points.Point>> dataPoints = points.getPoints().entrySet(); for (Map.Entry<Long, Points.Point> point : dataPoints) { data.add(toJSON(point.getKey(), point.getValue(), metricData.getUnit(), filterStats)); }/*from w ww. ja v a2 s .c o m*/ return data; }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java
public static JSONArray fullestoArray(String[] instance_group_keys, Jedis jedis) { JSONArray result = new JSONArray(); JSONObject info = new JSONObject(); for (int i = 0; i < instance_group_keys.length; ++i) { String[] instancesOfGroup = jedis.smembers(instance_group_keys[i]).toArray(new String[0]); for (int j = 0; j < instancesOfGroup.length; ++j) { info = new JSONObject(); info.put("name", instancesOfGroup[j]); result.add(info);//w w w . jav a 2 s.c om } } return result; }
From source file:com.mobicage.rogerthat.MessageCallbackResult.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a v a 2 s . c o m*/ public JSONObject toJSONObject() { final JSONObject result = new JSONObject(); result.put("message", message); final JSONArray answerArray = new JSONArray(); for (Answer answer : answers) { answerArray.add(answer.toJSONObject()); } result.put("answers", answerArray); result.put("flags", flags); result.put("branding", branding); result.put("tag", tag); result.put("alert_flags", alertFlags); result.put("dismiss_button_ui_flags", dismissButtonUiFlags); return result; }
From source file:mypackage.products.java
private String getResults(String query, String... params) { JSONArray jArray = new JSONArray(); StringBuilder sb = new StringBuilder(); Boolean isSingle = false;//www . j av a2 s.c om try (Connection cn = Credentials.getConnection()) { PreparedStatement pstmt = cn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); isSingle = true; } ResultSet rs = pstmt.executeQuery(); if (isSingle == false) { while (rs.next()) { JSONObject json = new JSONObject(); json.put("productId", rs.getInt("productId")); json.put("name", rs.getString("name")); json.put("description", rs.getString("description")); json.put("quantity", rs.getInt("quantity")); jArray.add(json); } } else { while (rs.next()) { JsonObject jsonObj = Json.createObjectBuilder().add("productId", rs.getInt("productId")) .add("name", rs.getString("name")).add("description", rs.getString("description")) .add("quantity", rs.getInt("quantity")).build(); return jsonObj.toString(); } } } catch (SQLException ex) { Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex); } return jArray.toJSONString(); }