List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:ch.zhaw.icclab.tnova.expressionsolver.Base.java
@GET @Produces(MediaType.APPLICATION_JSON)//from w w w .j a v a 2s . c om public String homePage() { KPI.api_calls += 1; JSONObject obj = new JSONObject(); obj.put("src", "t-nova expression evaluation service"); obj.put("msg", "api summary list"); JSONArray apiList = new JSONArray(); JSONObject api = new JSONObject(); api.put("uri", "/"); api.put("method", "GET"); api.put("purpose", "capability discovery"); apiList.add(api); api = new JSONObject(); api.put("uri", "/template/"); api.put("method", "GET"); api.put("purpose", "list of registered expression templates"); apiList.add(api); api = new JSONObject(); api.put("uri", "/template/"); api.put("method", "POST"); api.put("purpose", "registration of a new expression template"); apiList.add(api); api = new JSONObject(); api.put("uri", "/template/{id}"); api.put("method", "GET"); api.put("purpose", "get specific expression template details"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/{id}"); api.put("method", "DELETE"); api.put("purpose", "delete specific expression template, all expression instantiation will be deleted"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/"); api.put("method", "GET"); api.put("purpose", "list of registered expressions"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/"); api.put("method", "POST"); api.put("purpose", "register a new expression"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/{id}"); api.put("method", "GET"); api.put("purpose", "get specific expression details"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/{id}"); api.put("method", "PUT"); api.put("purpose", "update a specific expression"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/{id}"); api.put("method", "POST"); api.put("purpose", "execute a specific expression"); apiList.add(api); api = new JSONObject(); api.put("uri", "/expression/{id}"); api.put("method", "DELETE"); api.put("purpose", "delete a specific expression"); apiList.add(api); api = new JSONObject(); api.put("uri", "/kpi"); api.put("method", "GET"); api.put("purpose", "get the service key runtime metrics"); apiList.add(api); api = new JSONObject(); api.put("uri", "/otfly/"); api.put("method", "POST"); api.put("purpose", "on the fly stateless expression evaluation"); api.put("op-supported", "lt, gt, add, max, min, avg"); apiList.add(api); obj.put("api", apiList); logger.info("URI:/ Method:GET Request procesed."); KPI.api_calls_success += 1; return obj.toJSONString(); }
From source file:model.Post_store.java
public static int getlastid() { JSONParser parser = new JSONParser(); int lastid = 1; try {// ww w. jav a 2s . c om Object idObj = parser.parse(new FileReader(root + "posts/lastid.json")); JSONObject jsonObject = (JSONObject) idObj; String slastid = jsonObject.get("lastid").toString(); lastid = Integer.parseInt(slastid); //System.out.println(lastid); } catch (FileNotFoundException e) { JSONObject newIdObj = new JSONObject(); lastid = 1; newIdObj.put("lastid", lastid); try (FileWriter file = new FileWriter(root + "posts/lastid.json");) { file.write(newIdObj.toJSONString()); file.flush(); file.close(); } catch (IOException ex) { System.out.println(e); } } catch (IOException e) { System.out.println(e); } catch (ParseException e) { System.out.println(e); } return lastid; }
From source file:br.bireme.mlts.utils.Document2JSON.java
public static JSONObject getJSON(final Map<String, List<Fieldable>> map) { if (map == null) { throw new NullPointerException("map"); }//from w w w .j av a2 s . com final JSONObject jobj = new JSONObject(); for (Map.Entry<String, List<Fieldable>> entry : map.entrySet()) { final String key = entry.getKey(); final List<Fieldable> value = entry.getValue(); final boolean multivalue = value.size() > 1; if (multivalue) { final JSONArray array = new JSONArray(); jobj.put(key, array); for (Fieldable fld : value) { array.add(getObject(fld)); } } else { jobj.put(key, getObject(value.get(0))); } } return jobj; }
From source file:de.hstsoft.sdeep.Configuration.java
@SuppressWarnings("unchecked") public void save() { JSONObject jsonObject = new JSONObject(); jsonObject.put(PREF_SAVEGAME_PATH, saveGamePath); jsonObject.put(PREF_AUTOREFRESH, autorefresh); try {//w ww . j a va 2 s .c om String jsonString = jsonObject.toJSONString(); FileWriter fileWriter = new FileWriter(configFile); fileWriter.append(jsonString); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:MyGCListener.java
@SuppressWarnings("unchecked") public void gcEvent(GCEvent event) { //System.out.println("I've been called in myGCListener"); obj.put("timestamp", event.getEventTime()); JSONObject gc = new JSONObject(); gc.put("type", event.getType()); gc.put("size", event.getHeapSize()); gc.put("used", event.getUsedHeapAfterGC()); gc.put("duration", event.getPauseTime()); obj.put("gc", gc); IndexResponse response = eSC.getClient().prepareIndex(eSC.getIndex(), "gc").setSource(obj.toJSONString()) .get();/*from w ww.j a va 2 s . c o m*/ }
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)); }
From source file:de.Keyle.MyPet.util.configuration.ConfigurationJSON.java
public JSONObject getJSONObject() { if (config == null) { config = new JSONObject(); } return config; }
From source file:login.login_servlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject arrayObj = new JSONObject(); try {/* w w w. j a va2s . com*/ LoginBean user = new LoginBean(); user.setUsername(request.getParameter("EmailorUsername")); user.setPassword(request.getParameter("password")); int userID = 0; user = LoginDAO.login(user); System.out.println(user.isValid()); if (user.isValid()) { String token = generateToken(20); userID = LoginDAO.getUserID(user); arrayObj.put("access_token", token); arrayObj.put("user_id", ((Integer) userID).toString()); arrayObj.put("username", user.getUsername()); arrayObj.put("status", "ok"); System.out.println(token); System.out.println(((Integer) userID).toString()); System.out.println(user.getUsername()); String query = "INSERT INTO tokendata(user_id, token, create_time) VALUES ('" + userID + "','" + token + "',NOW())"; //to trace the process in console System.out.println("Your user name is " + user.getUsername()); System.out.println("Your token is " + token); System.out.println("Query: " + query); Connection currentCon = null; currentCon = ConnectionManager.getConnection(); try { //connect to database PreparedStatement ps = currentCon.prepareStatement(query); int i = ps.executeUpdate(); System.out.println("TOKEN MASUK DATABASE"); } catch (Exception ex) { System.out.println("Register failed: An Exception has occurred! " + ex); } finally { if (currentCon != null) { try { currentCon.close(); } catch (Exception e) { } currentCon = null; } } //RequestDispatcher rd=request.getRequestDispatcher("catalog.jsp"); //System.out.println("wkwk"); //rd.forward(request,response); //System.out.println("wkwkwk"); } else { arrayObj.put("status", "error"); } response.setContentType("application/json:charset=UTF-8"); response.getWriter().write(arrayObj.toString()); } catch (Throwable theException) { System.out.println(theException); } }
From source file:com.mcapanel.web.controllers.SettingsController.java
@SuppressWarnings("unchecked") public boolean updateLicense() throws IOException { if (isMethod("POST")) { includeIndex(false);// w w w . j a v a2 s. c o m mimeType("application/json"); JSONObject obj = new JSONObject(); if (isLoggedIn() && user.getGroup().hasPermission("mcapanel.properties.edit")) { String licemail = request.getParameter("licemail"); String lickey = request.getParameter("lickey"); config.setValue("license-email", licemail); config.setValue("license-key", lickey); config.saveConfig(); obj.put("good", "Successfully updated your license!"); } else obj.put("error", "You do not have permission to do that."); response.getWriter().println(obj.toJSONString()); return true; } return error(); }
From source file:com.bigml.histogram.MapCategoricalTarget.java
@Override @SuppressWarnings("unchecked") protected void addJSON(JSONArray binJSON, DecimalFormat format) { JSONObject counts = new JSONObject(); for (Entry<Object, Double> categoryCount : _counts.entrySet()) { Object category = categoryCount.getKey(); double count = categoryCount.getValue(); counts.put(category, Utils.roundNumber(count, format)); }//w w w .j av a 2s . c om binJSON.add(counts); }