List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:myproject.MyServer.java
public static void List(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w ww . jav a2 s .com*/ String query = "SELECT * FROM student"; String result = database.runQuery(query); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:mysynopsis.JSONWriter.java
public static void writeData() throws IOException { JSONObject bio = new JSONObject(); bio.put("Name", name); bio.put("Initial", initial); bio.put("Bio", biog); bio.put("Designation", designation); bio.put("Department", dept); bio.put("University", university); bio.put("University_Address", universityAddress); bio.put("Office", office); bio.put("Ohours", officehours); bio.put("Phone", phone); bio.put("Email", email); bio.put("Resume_Link", resumelink); bio.put("Educational", education); bio.put("Professional", professional); bio.put("Awards", awards); bio.put("Image_Ext", imgExtension); bio.put("Image_String", imgString); /*JSONArray education = new JSONArray(); for(int i=0;i<8;i++) {/*w w w.j av a 2 s. co m*/ education.add(educ[i]); } bio.put("Education",education);*/ JSONArray ftpinfo = new JSONArray(); ftpinfo.add(server); ftpinfo.add(user); ftpinfo.add(dir); bio.put("Server_Information", ftpinfo); try (FileWriter file = new FileWriter("data.json")) { file.write(bio.toJSONString()); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Can't Create Data.json File. Please Check Your Directory Permission"); } }
From source file:autoancillarieslimited.parser.ParserUtil.java
public static String parserItemJSon(Item item) { JSONObject jSONObject = new JSONObject(); jSONObject.put("P0", item.getId()); jSONObject.put("P1", item.getName()); jSONObject.put("P3", item.getDescription()); jSONObject.put("P2", item.getTypeItem().getId()); jSONObject.put("P4", item.getPrice()); jSONObject.put("P6", item.getImages()); return jSONObject.toString(); }
From source file:myproject.MyServer.java
public static void Query(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w ww . j ava2 s . co m*/ String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); String query = (String) json.get("query"); String result = database.runQuery(query); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:myproject.MyServer.java
public static void Delete(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w w w . j ava 2 s .c om*/ String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); Long student_id = (Long) json.get("student_id"); String query = String.format("DELETE FROM student " + "WHERE student_id=%d", student_id); database.runUpdate(query); JSONObject output = new JSONObject(); output.put("result", true); response.getWriter().write(JSONValue.toJSONString(output)); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:manager.GameElement.java
public static JSONObject toJSON() { JSONObject json = new JSONObject(); json.put("level", String.valueOf(level)); json.put("experience", String.valueOf(experience)); json.put("streak", String.valueOf(streak)); return json;/*from w ww. j a v a2s . co m*/ }
From source file:myproject.MyServer.java
public static void Add(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from ww w. j ava 2s .co m*/ String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); String student_name = (String) json.get("student_name"); Long regno = (Long) json.get("regno"); Double cgpa = (Double) json.get("cgpa"); String query = String.format( "INSERT INTO student " + "(student_name, regno, cgpa) " + "VALUES('%s',%d,%f)", JSONValue.escape(student_name), regno, cgpa); database.runUpdate(query); String result = database.getStudent(regno); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
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);/*from w w w. j ava 2 s. co m*/ } return children.toJSONString(); }
From source file:com.wso2.raspberrypi.apicalls.APICall.java
public static void registerDevice(String deviceID, String zoneID) { String url = apiURLPrefix + "/conferences/2/iot/scannerZones/byScannerUUID"; Token token = getToken();/*from w ww . j a v a 2 s. co m*/ if (token != null) { HttpClient httpClient = new HttpClient(); JSONObject json = new JSONObject(); json.put("rfidScannerUUID", deviceID); json.put("zoneId", zoneID); try { HttpResponse httpResponse = httpClient.doPost(url, "Bearer " + token.getAccessToken(), json.toJSONString(), "application/json"); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != 200) { log.error("Device to Zone registration failed. HTTP Status Code:" + statusCode); } } catch (IOException e) { log.error("", e); } } }
From source file:myproject.MyServer.java
public static void Update(HttpServletRequest request, HttpServletResponse response) throws IOException { try {// w w w . ja v a 2 s .com String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); Long student_id = (Long) json.get("student_id"); String student_name = (String) json.get("student_name"); Long regno = (Long) json.get("regno"); Double cgpa = (Double) json.get("cgpa"); String query = String.format( "UPDATE student " + "SET student_name='%s'," + "regno=%d," + "cgpa=%f " + "WHERE student_id=%d", JSONValue.escape(student_name), regno, cgpa, student_id); database.runUpdate(query); String result = database.getStudent(regno); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }