List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.fujitsu.dc.engine.rs.StatusResource.java
/** * GET???.//from w ww .j a v a 2 s . c o m * @return JAS-RS Response */ @SuppressWarnings("unchecked") @GET @Produces("application/json") public Response get() { StringBuilder sb = new StringBuilder(); // Properties props = DcEngineConfig.getProperties(); JSONObject responseJson = new JSONObject(); JSONObject propertiesJson = new JSONObject(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); propertiesJson.put(key, value); } responseJson.put("properties", propertiesJson); sb.append(responseJson.toJSONString()); return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build(); }
From source file:io.personium.engine.rs.StatusResource.java
/** * GET???./*from ww w .j a va 2 s. co m*/ * @return JAS-RS Response */ @SuppressWarnings("unchecked") @GET @Produces("application/json") public Response get() { StringBuilder sb = new StringBuilder(); // Properties props = PersoniumEngineConfig.getProperties(); JSONObject responseJson = new JSONObject(); JSONObject propertiesJson = new JSONObject(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); propertiesJson.put(key, value); } responseJson.put("properties", propertiesJson); sb.append(responseJson.toJSONString()); return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build(); }
From source file:net.bashtech.geobot.JSONUtil.java
public static String incVar(String channel, String varName, int incValue) { JSONObject postData = new JSONObject(); postData.put("incAmount", incValue); try {//from w w w . j av a 2 s . c om JSONParser parser = new JSONParser(); String resp = BotManager.postCoebotVars(postData.toJSONString(), "http://coebot.tv/api/v1/vars/increment/" + varName + "/" + channel); if (!resp.equals("")) { Object obj = parser.parse(resp); JSONObject jsonObject = (JSONObject) obj; String status = (String) (jsonObject.get("status")); if (status.equals("ok")) { String newValue = (String) jsonObject.get("newValue"); return newValue; } else { return null; } } else { return null; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:net.bashtech.geobot.JSONUtil.java
public static String decVar(String channel, String varName, int incValue) { incValue *= -1;/* w ww. ja v a 2s. co m*/ JSONObject postData = new JSONObject(); postData.put("incAmount", incValue); try { JSONParser parser = new JSONParser(); String resp = BotManager.postCoebotVars(postData.toJSONString(), "http://coebot.tv/api/v1/vars/increment/" + varName + "/" + channel); if (!resp.equals("")) { Object obj = parser.parse(resp); JSONObject jsonObject = (JSONObject) obj; String status = (String) (jsonObject.get("status")); if (status.equals("ok")) { String newValue = (String) jsonObject.get("newValue"); return newValue; } else { return null; } } else { return null; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:cpd4414.assign2.OrderQueue.java
String generateReport() { String output = ""; if (!(orderQueue.isEmpty() && ListOfOrder.isEmpty())) { JSONObject obj = new JSONObject(); JSONArray orders = new JSONArray(); for (Order o : ListOfOrder) { orders.add(o.tojsonconvert()); }// w w w . j av a2 s. c o m for (Order o : orderQueue) { orders.add(o.tojsonconvert()); } obj.put("orders", orders); output = obj.toJSONString(); } return output; }
From source file:cn.vlabs.duckling.vwb.PromitionLogFilter.java
private void logCreateJson(String referHostName, String requestUrl) { JSONObject obj = new JSONObject(); obj.put("type", "create"); obj.put("referHost", "-"); obj.put("referHostName", referHostName); obj.put("referer", "-"); obj.put("requestUrl", requestUrl); obj.put("logDate", formatData2String(new Date(), "yyyy-MM-dd HH:mm:ss")); log.info(obj.toJSONString()); }
From source file:naftoreiclag.villagefive.world.World.java
@Override public String toJSONString() { JSONObject json = new JSONObject(); json.put("name", name); json.put("entities", entities); json.put("plots", plots); return json.toJSONString(); }
From source file:com.pjaol.ESB.formatters.JSONFormatter.java
private String iterateNamedList(NamedList output) { JSONObject jo = new JSONObject(); int sz = output.size(); for (int i = 0; i < sz; i++) { String k = output.getName(i); Object v = output.getVal(i); if (v instanceof NamedList) { jo.put(k, recurseNamedList((NamedList) v)); } else {/* ww w.ja va 2 s . c om*/ jo.put(k, v); } } return jo.toJSONString(); }
From source file:com.example.networkPacketFormats.ServeFunction.java
public String getJSONQuestionsString(String sub, String date, String standard) { PreparedStatement p;/*from w w w . j a v a2s .c om*/ try { p = (PreparedStatement) con.prepareStatement("select * from question_table" + " where subject='" + sub + "' and date >='" + date + "'" + " and " + "std='" + standard + "'"); ResultSet result = p.executeQuery(); /* Form a HashMap and add into it */ HashMap<String, String> hm = new HashMap<>(); while (result.next()) { String ques = result.getString("question"); String ans = result.getString("answer"); String level = result.getString("level"); String datey = result.getString("date"); ans = level + "$" + datey + "$" + ans; hm.put(ques, ans); } /* Now form a JSON Object */ JSONObject jobj = new JSONObject(hm); System.out.println(jobj.toJSONString()); return jobj.toJSONString(); } catch (SQLException ex) { Logger.getLogger(ServeFunction.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.appzone.sim.services.handlers.AppRegistrationServiceHandlerTest.java
public void testServeConfigureInfoRequest() { final HttpServletRequest request = context.mock(HttpServletRequest.class); AppRegistrationServiceHandler handler = new AppRegistrationServiceHandler(); context.checking(new Expectations() { {/*from w ww. j a va 2 s.c om*/ allowing(request).getParameter(DefaultKewordMatcher.SERVICE_KEYWORD); will(returnValue(AppRegistrationServiceHandler.MATCHING_KEYWORD)); allowing(request).getParameter(AppRegistrationServiceHandler.KEY_INFO_REQUEST); will(returnValue("true")); allowing(request).getParameter(AppRegistrationServiceHandler.KEY_URL); will(returnValue("the url")); allowing(request).getParameter(AppRegistrationServiceHandler.KEY_USERNAME); will(returnValue("the username")); allowing(request).getParameter(AppRegistrationServiceHandler.KEY_PASSWORD); will(returnValue("the password")); } }); JSONObject json = new JSONObject(); Application.configure("http://url", "username", "password"); json.put(AppRegistrationServiceHandler.JSON_KEY_URL, "http://url"); json.put(AppRegistrationServiceHandler.JSON_KEY_USERNAME, "username"); json.put(AppRegistrationServiceHandler.JSON_KEY_PASSWORD, "password"); assertEquals(json.toJSONString(), handler.serve(request)); }