List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:com.ibm.storlet.common.StorletObjectOutputStream.java
@SuppressWarnings("unchecked") public void setMetadata(Map<String, String> md) throws StorletException { JSONObject jobj = new JSONObject(); Iterator<Map.Entry<String, String>> it = md.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next(); jobj.put((String) pairs.getKey(), (String) pairs.getValue()); it.remove();// w w w .ja va 2s . c o m } try { MetadataStream_.write(jobj.toString().getBytes()); MetadataStream_.close(); } catch (IOException e) { throw new StorletException("Failed to set metadata " + e.toString()); } }
From source file:emcali.ami.control.webservice.IPTVAMIWebService.java
/** * This is a sample web service operation * * @param args/*from w ww.j av a 2 s . c o m*/ * @return */ @WebMethod(operationName = "execute") public String execute(@WebParam(name = "args") String args) { JSONObject jsonResponse = new JSONObject(); try { JSONParser parser = new JSONParser(); Object obj = parser.parse(args); JSONObject jsonRequest = (JSONObject) obj; String user = (String) jsonRequest.get("user"); String password = (String) jsonRequest.get("password"); Credentials credentials = new Credentials(); String message = credentials.authenticate(user, password); switch (message) { case "user unauthorized": jsonResponse.put("type", "error"); jsonResponse.put("message", message); break; case "wrong password": jsonResponse.put("type", "error"); jsonResponse.put("message", message); break; case "success": jsonResponse.put("type", "info"); jsonResponse.put("message", message); if (((String) jsonRequest.get("command")).equals("getData")) { jsonResponse = this.getData(jsonRequest, jsonResponse); } break; } return jsonResponse.toJSONString(); } catch (ParseException ex) { jsonResponse.put("type", "error"); jsonResponse.put("message", "JSON Format error: " + ex.getMessage()); return jsonResponse.toJSONString(); } }
From source file:com.megacasting_ppe.web.ServletOffresLibelle.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www.j a v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //on rcupre la valeur recupr du moteur de recherche. String Libelle = request.getParameter("libelle_recherche"); HttpSession session = request.getSession(); JSONObject global = new JSONObject(); JSONArray arrayoffre = new JSONArray(); ArrayList<Offre> listOffresSearch = new ArrayList(); for (Offre offre : offreDAO.Lister()) { if (recherche(offre.getLibelle(), Libelle) > 0) { listOffresSearch.add(offre); } } for (Offre offre : listOffresSearch) { JSONObject object = new JSONObject(); object.put("Identifiant", offre.getIdentifiant()); object.put("Intitule", offre.getLibelle()); object.put("Reference", offre.getReference()); object.put("DateDebutContrat", offre.getDateDebutContrat().toString()); object.put("NombresPoste", offre.getNbPoste()); object.put("VilleEntreprise", offre.getClient().getVilleEntreprise()); arrayoffre.add(object); } global.put("offres", arrayoffre); global.put("container_search", Libelle); session.setAttribute("offres_lib", global); RequestDispatcher rq = request.getRequestDispatcher("offres.html"); rq.forward(request, response); }
From source file:es.tid.fiware.fiwareconnectors.cygnus.backends.ckan.CKANResponseTest.java
/** * Sets up tests by creating a unique instance of the tested class, and by defining the behaviour of the mocked * classes./*from w w w. j a v a2s .com*/ * * @throws Exception */ @Before public void setUp() throws Exception { // set up the instance of the tested class JSONObject obj = new JSONObject(); obj.put("test", "test"); response = new CKANResponse(obj, 200); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Sonar.java
@SuppressWarnings("unchecked") @Override/*w ww.ja va 2s . com*/ public String toJSONString() { JSONObject o = new JSONObject(); o.put("type", ISensorProxy.SENSOR_NAME_SONAR); if (getTimestamp() != 0) { o.put("time", getTimestamp()); o.put("value", sonar); } return o.toJSONString(); }
From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java
public static String getStates(String statesFilePath) throws ParserConfigurationException, IOException, SAXException { JSONObject statesFeatureCollection = new JSONObject(); statesFeatureCollection.put("type", "FeatureCollection"); JSONArray features = new JSONArray(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {// www .jav a 2 s .c o m DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document dom = documentBuilder.parse(new FileInputStream(new File(statesFilePath))); Element docElement = dom.getDocumentElement(); NodeList states = docElement.getElementsByTagName("state"); for (int i = 0; i < states.getLength(); i++) { Node state = states.item(i); JSONObject stateObj = new JSONObject(); stateObj.put("type", "Feature"); JSONObject geometry = new JSONObject(); geometry.put("type", "Polygon"); JSONArray coordinates = new JSONArray(); JSONArray coordinateSub = new JSONArray(); NodeList points = ((Element) state).getElementsByTagName("point"); for (int j = 0; j < points.getLength(); j++) { Node point = points.item(j); JSONArray pointObj = new JSONArray(); float lat = Float.parseFloat(((Element) point).getAttribute("lat")); float lng = Float.parseFloat(((Element) point).getAttribute("lng")); double trLng = lng * 20037508.34 / 180; double trLat = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); pointObj.add(lng); pointObj.add(lat); coordinateSub.add(pointObj); } geometry.put("coordinates", coordinates); coordinates.add(coordinateSub); stateObj.put("geometry", geometry); JSONObject name = new JSONObject(); name.put("Name", ((Element) state).getAttribute("name")); name.put("colour", "#FFF901"); stateObj.put("properties", name); features.add(stateObj); } statesFeatureCollection.put("features", features); return statesFeatureCollection.toJSONString(); } catch (ParserConfigurationException e) { log.error("Error while processing states.xml.", e); throw e; } catch (FileNotFoundException e) { log.error("Error while processing states.xml.", e); throw e; } catch (SAXException e) { log.error("Error while processing states.xml.", e); throw e; } catch (IOException e) { log.error("Error while processing states.xml.", e); throw e; } }
From source file:net.duckling.ddl.web.api.APIUserInfoController.java
@RequestMapping public void getUserInfo(HttpServletRequest req, HttpServletResponse resp) { JSONObject object = new JSONObject(); String uid = req.getParameter("uid"); String id = req.getParameter("id"); if (StringUtils.isEmpty(uid) && StringUtils.isEmpty(id)) { object.put("result", false); object.put("message", "??id??"); JsonUtil.writeJSONObject(resp, object); return;//from w w w. ja v a 2 s. c o m } UserExt user = null; if (StringUtils.isNotEmpty(uid)) { user = aoneUserService.getUserExtInfo(uid); } if (StringUtils.isNotEmpty(id)) { int i = Integer.parseInt(id); user = aoneUserService.getUserExtByAutoID(i); } if (user != null) { putJson("result", true, object); putJson("id", user.getId(), object); putJson("uid", user.getUid(), object); putJson("address", user.getAddress(), object); putJson("birthday", user.getBirthday(), object); putJson("department", user.getDepartment(), object); putJson("email", user.getEmail(), object); putJson("mobile", user.getMobile(), object); putJson("name", user.getName(), object); putJson("sex", user.getSex(), object); putJson("telephone", user.getTelephone(), object); putJson("qq", user.getQq(), object); putJson("weibo", user.getWeibo(), object); putJson("orgnization", user.getOrgnization(), object); } else { object.put("result", false); object.put("message", "??id??"); } JsonUtil.writeJSONObject(resp, object); }
From source file:com.ba.reports.DayReport.BADayReportAction.java
public ActionForward baView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("view()"); JSONObject json = new JSONObject(); BADayReportDTO vo = new BADayReportDTO(); try {// w w w . ja v a2s . co m logger.info(" view method starts here"); String fromDate = request.getParameter("fromDate"); String toDate = request.getParameter("toDate"); List hashMpRoomItemDet = BADayReportFactory.getInstanceOfBADayReportFactory().getRoomDtls(1, fromDate, toDate); objPageCount = BADayReportFactory.getInstanceOfBADayReportFactory().getPageCount(fromDate, toDate); json.put("exception", ""); json.put("RoomDets", hashMpRoomItemDet); json.put("RoomExit", hashMpRoomItemDet.size()); json.put("objPageCount", objPageCount); logger.warn("strCurrent PageNo ------------->" + objPageCount); } catch (Exception ex) { logger.error("The Exception is :" + ex); ex.printStackTrace(); json.put("exception", BAHandleAllException.exceptionHandler(ex)); } response.getWriter().write(json.toString()); return null; }
From source file:cz.alej.michalik.totp.server.User.java
/** * Zsk uivatelsk jmno obsaen v URI/*from www . j ava2s .c om*/ */ public void doInit() { // Pokud metoda nezmn stav, stala se chyba msg = new JSONObject(); msg.put("status", "error"); this.user = getAttribute("id"); if (!Data.exists(user)) { user = null; msg.put("exists", "0"); msg.put("message", "User does not exist"); } else { msg.put("exists", "1"); } }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Random.java
@SuppressWarnings("unchecked") @Override//from w w w. j a v a 2 s . co m public String toJSONString() { JSONObject o = new JSONObject(); o.put("type", ISensorProxy.SENSOR_NAME_RANDOM); if (getTimestamp() != 0) { o.put("time", getTimestamp()); o.put("value", random); } return o.toJSONString(); }